[Erp5-report] r9970 - in /erp5/trunk/products: ERP5/tests/ ERP5Type/

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Sep 15 11:48:45 CEST 2006


Author: alex
Date: Fri Sep 15 11:48:43 2006
New Revision: 9970

URL: http://svn.erp5.org?rev=9970&view=rev
Log:
_edit() must not detect a property modified in a interaction workflow script
as modified by the user

Modified:
    erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py
    erp5/trunk/products/ERP5Type/Base.py

Modified: erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py?rev=9970&r1=9969&r2=9970&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py (original)
+++ erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py Fri Sep 15 11:48:43 2006
@@ -424,6 +424,42 @@
     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:

Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=9970&r1=9969&r2=9970&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py (original)
+++ erp5/trunk/products/ERP5Type/Base.py Fri Sep 15 11:48:43 2006
@@ -984,6 +984,7 @@
       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 @@
         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 != {}):




More information about the Erp5-report mailing list