Commit bc3b5a25 authored by Jérome Perrin's avatar Jérome Perrin

Fix clone behavior on transformations

Fix for [#20160719-1B69F57]( https://nexedi.erp5.net/bug_module/20160719-1B69F57 ) 

These after clone methods in transformed resources are being too clever and behave very badly when the transformation itself is cloned.

The suggested approach is to stop initializing int index & reference when cloning transformed resources ("transformation lines"). This behavior is kept when adding new transformed resource. This become consistent with what we have, for example, with Sale Order Lines in Sale Orders. 

/cc @luke @seb @gabriel @kazuhiko @romain @Nicolas 

( see also nexedi/erp5!148 for more )


/reviewed-on nexedi/erp5!258
parents 113d04ca 9c04e13c
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args, **kw</string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TransformationOperation_afterClone</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Guard" module="Products.DCWorkflow.Guard"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>roles</string> </key>
<value>
<tuple>
<string>Owner</string>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args, **kw</string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TransformationOptionalResource_afterClone</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Guard" module="Products.DCWorkflow.Guard"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>roles</string> </key>
<value>
<tuple>
<string>Owner</string>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args, **kw</string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TransformationTransformedResource_afterClone</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Guard" module="Products.DCWorkflow.Guard"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>roles</string> </key>
<value>
<tuple>
<string>Owner</string>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -335,6 +335,50 @@ class TestMRPImplementation(TestMRPMixin):
(self.consumed_resource_2, -10.0, None)]
self.checkExpectedLineList(production_report, expected_line_list)
def _test_add_and_clone_tranformed_resource(self, portal_type):
test_product = self.portal.product_module.newContent()
transformation = self.portal.transformation_module.newContent(
portal_type='Transformation',
reference='TR1',
resource_value=test_product)
transformed_resource = transformation.newContent(
portal_type=portal_type)
# transformation transformed resource is initialised with int index
self.assertEqual(1, transformed_resource.getIntIndex())
transformed_resource_2 = transformation.newContent(
portal_type=portal_type)
# int index increments as the number of lines increase
self.assertEqual(2, transformed_resource_2.getIntIndex())
transformed_resource_2.setReference('user defined reference')
# when cloning a transformation transformed resource, int index is also
# cloned and not incremented.
transformed_resource_3 = transformed_resource_2.Base_createCloneDocument(batch_mode=True)
self.assertEqual(2, transformed_resource_3.getIntIndex())
self.assertEqual('user defined reference', transformed_resource_3.getReference())
# Cloning a transformation properly keep the transformation transformed resources references
transformed_resource_2.setIntIndex(123)
transformation_2 = transformation.Base_createCloneDocument(batch_mode=True)
self.assertEqual(1, transformation_2['1'].getIntIndex())
self.assertEqual(123, transformation_2['2'].getIntIndex())
self.assertEqual(2, transformation_2['3'].getIntIndex())
self.assertEqual('user defined reference', transformation_2['2'].getReference())
def test_add_and_clone_transformation_transformed_resource(self):
self._test_add_and_clone_tranformed_resource('Transformation Transformed Resource')
def test_add_and_clone_transformation_optional_resource(self):
self._test_add_and_clone_tranformed_resource('Transformation Optional Resource')
def test_add_and_clone_transformation_operation(self):
self._test_add_and_clone_tranformed_resource('Transformation Operation')
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestMRPImplementation))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment