Commit 6f6c628c authored by Alexandre Boeglin's avatar Alexandre Boeglin

_edit() must not detect a property modified in a interaction workflow script

as modified by the user


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9970 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c63ae6fb
......@@ -424,6 +424,42 @@ class TestInteractionWorkflow(ERP5TypeTestCase):
self.assertEquals(organisation.getVatCode(),'fooa')
self.assertEquals(organisation.getDefaultEmailText(),'bar')
def test_13(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
self.logMessage('Interactions, Check that edit does not detect the '
'property modified in interaction script as modified by user')
self.createInteractionWorkflow()
self.interaction.setProperties(
'afterEdit',
method_id='setTitle',
after_script_name=('afterEdit',))
params = 'sci,**kw'
body = "context = sci.object\n" +\
"vat_code = context.getVatCode()\n" +\
"if vat_code is None:\n" +\
" vat_code = ''\n" +\
"context.setVatCode(vat_code + 'a')"
self.script.ZPythonScript_edit(params,body)
self.createData()
organisation = self.organisation
organisation.setTitle('foo')
organisation.setVatCode('bar')
self.assertEquals(organisation.getTitle(), 'foo')
self.assertEquals(organisation.getVatCode(), 'bar')
organisation.edit(title='baz', vat_code='bar')
self.assertEquals(organisation.getTitle(),'baz')
# here, the wrong behaviour was:
# - edit:setTitle(baz)
# - interaction:setVatCode(bara)
# - edit:setVatCode(bar)
# whereas, the correct order is:
# - edit:setTitle(baz)
# - edit:setVatCode(bar)
# - interaction:setVatCode(bara)
self.assertEquals(organisation.getVatCode(),'bara')
if __name__ == '__main__':
framework()
else:
......
......@@ -984,6 +984,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
be updated through this generic edit method
"""
self._v_modified_property_dict = {}
my_modified_property_list = []
for key in kw.keys():
if key != 'id':
# We only change if the value is different
......@@ -999,12 +1000,16 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
if old_value != kw[key] or force_update:
# We keep in a thread var the previous values
# this can be useful for interaction workflow to implement lookups
# XXX If iteraction workflow script is triggered by edit and calls
# edit itself, this is useless as the dict will be overwritten
self._v_modified_property_dict[key] = old_value
self._setProperty(key, kw[key])
my_modified_property_list.append(key)
elif self.id != kw['id']:
self.setId(kw['id'], reindex=reindex_object)
# Modification date is supported by edit_workflow in ERP5
# There is no need to change it here
for key in my_modified_property_list:
self._setProperty(key, kw[key])
if reindex_object:
# We do not want to reindex the object if nothing is changed
if (self._v_modified_property_dict != {}):
......
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