diff --git a/product/ERP5Type/Constraint/PropertyTypeValidity.py b/product/ERP5Type/Constraint/PropertyTypeValidity.py index 0ee0f111b6f1cea563db3406b77f3b659cdf639f..ca0b0e9b68b4fcf4baede04d4bdae9ca376fc8f2 100644 --- a/product/ERP5Type/Constraint/PropertyTypeValidity.py +++ b/product/ERP5Type/Constraint/PropertyTypeValidity.py @@ -91,6 +91,15 @@ class PropertyTypeValidity(Constraint): property_type = 'lines' else: property_type = prop['type'] + + # if this property was a local property and has been later added in a + # property sheet, we want to remove it from _local_properties + if fixit and \ + property_id in [x['id'] for x in obj._local_properties] and \ + len([x for x in obj._propertyMap() if x['id'] == property_id]) > 1: + obj._local_properties = tuple([x for x in obj._local_properties + if x['id'] != property_id]) + if property_type in self._permissive_type_list: continue wrong_type = 0 @@ -134,4 +143,5 @@ class PropertyTypeValidity(Constraint): oldvalue = getattr(obj, property_id, value) if oldvalue != value: obj.setProperty(property_id, oldvalue) + return error_list diff --git a/product/ERP5Type/tests/testConstraint.py b/product/ERP5Type/tests/testConstraint.py index 9a1804ea13d2c49e89108af253331e83b711fd24..7fd7f85fe30c13e8ec6324b98879489c2d301a06 100644 --- a/product/ERP5Type/tests/testConstraint.py +++ b/product/ERP5Type/tests/testConstraint.py @@ -1184,23 +1184,45 @@ class TestConstraint(PropertySheetTestCase): expression='error: " ') self.assertRaises(CompilerError, constraint.checkConsistency, obj) - def test_PropertyTypeValidityFixLocalProperties(self): + def test_PropertyTypeValidityFixLocalPropertiesString(self): """Tests PropertyTypeValidity can repairs local property when this property - is added on the class later. + is added on the class later, and this property is already in the good type. """ constraint = self._createGenericConstraint( klass_name='PropertyTypeValidity', id='type_validity_constraint', ) obj = self._makeOne() obj.edit(local_property='1') + self.assertEquals(1, len(obj._local_properties)) self.assertEquals([], constraint.checkConsistency(obj)) # now add a 'local_property' property defined on a property sheet self._addProperty(obj.getPortalType(), - '''{'id': 'local_property', 'type': 'int'}''') + '''{'id': 'local_property', 'type': 'string'}''') + constraint.fixConsistency(obj) + self.assertEquals((), obj._local_properties) + self.assertEquals('1', obj.getLocalProperty()) + obj.edit(local_property='something else') + self.assertEquals('something else', obj.getLocalProperty()) + + def test_PropertyTypeValidityFixLocalPropertiesFloat(self): + """Tests PropertyTypeValidity can repairs local property when this property + is added on the class later, and this property type changed. + """ + constraint = self._createGenericConstraint( + klass_name='PropertyTypeValidity', + id='type_validity_constraint', ) + obj = self._makeOne() + obj.edit(local_property=1.234) + self.assertEquals(1, len(obj._local_properties)) + #self.assertEquals([], constraint.checkConsistency(obj)) + # now add a 'local_property' property defined on a property sheet + self._addProperty(obj.getPortalType(), + '''{'id': 'local_property', 'type': 'float'}''') constraint.fixConsistency(obj) - self.assertEquals(1, obj.getLocalProperty()) + self.assertEquals((), obj._local_properties) + self.assertEquals(1.234, obj.getLocalProperty()) obj.edit(local_property=3) - self.assertEquals(3, obj.getLocalProperty()) + self.assertEquals(3., obj.getLocalProperty()) def test_PropertyTypeValidityFixLocalPropertiesContent(self): """Tests PropertyTypeValidity can repairs local property of type content