[Erp5-report] r35805 kazuhiko - /erp5/trunk/products/ERP5Legacy/Document/Rule.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon May 31 17:36:53 CEST 2010


Author: kazuhiko
Date: Mon May 31 17:36:47 2010
New Revision: 35805

URL: http://svn.erp5.org?rev=35805&view=rev
Log:
merge _getCompensatedMovementListBPM() and _getCompensatedMovementList() still keeping their current behaviours.

Modified:
    erp5/trunk/products/ERP5Legacy/Document/Rule.py

Modified: erp5/trunk/products/ERP5Legacy/Document/Rule.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Legacy/Document/Rule.py?rev=35805&r1=35804&r2=35805&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Legacy/Document/Rule.py [utf8] (original)
+++ erp5/trunk/products/ERP5Legacy/Document/Rule.py [utf8] Mon May 31 17:36:47 2010
@@ -361,11 +361,13 @@
 
     return input_movement_and_path_list
 
-  def _getCompensatedMovementListBPM(self, applied_rule, **kw):
+  def _getCompensatedMovementList(self, applied_rule,
+                                  matching_property_list=None, **kw):
     """Compute the difference between prevision and existing movements
 
     Immutable movements need compensation, mutable ones needs to be modified
     """
+    is_bpm = self._isBPM()
     add_list = [] # list of movements to be added
     modify_dict = {} # dict of movements to be modified
     delete_list = [] # list of movements to be deleted
@@ -378,10 +380,13 @@
                     + deletable_movement_list
     non_matched_list = movement_list[:] # list of remaining movements
 
+    if matching_property_list is None:
+      matching_property_list = self.getMatchingPropertyList()
+
     for prevision in prevision_list:
       p_matched_list = []
       for movement in non_matched_list:
-        for prop in self.getMatchingPropertyList():
+        for prop in matching_property_list:
           if movement.isPropertyRecorded(prop):
             movement_value = movement.getRecordedProperty(prop)
           else:
@@ -414,13 +419,19 @@
               break
           else:
             # no modifiable movement was found, need to compensate by quantity
-            raise NotImplementedError('Need to generate quantity compensation in %s, because all matched movements are immutable : %r.' % (applied_rule.getRelativeUrl(), [x.getRelativeUrl() for x in p_matched_list]))
+            if is_bpm:
+              raise NotImplementedError('Need to generate quantity compensation in %s, because all matched movements are immutable : %r.' % (applied_rule.getRelativeUrl(), [x.getRelativeUrl() for x in p_matched_list]))
+            else:
+              prevision['quantity'] = q_diff
+              add_list.append(prevision)
 
         for movement in p_matched_list:
           if movement in (mutable_movement_list \
               + deletable_movement_list):
             prop_dict = modify_dict.setdefault(movement.getId(), {})
             for k, v in prevision.items():
+              if k in ('quantity',):
+                pass
               if movement.isPropertyRecorded(k):
                 movement_value = movement.getRecordedProperty(k)
                 if isinstance(movement_value, list) and not isinstance(v, list):
@@ -430,7 +441,7 @@
                     movement_value = None
               else:
                 movement_value = movement.getProperty(k)
-              if k not in ('quantity',) and v != movement_value:
+              if v != movement_value:
                 prop_dict.setdefault(k, v)
 
         # update movement lists
@@ -456,129 +467,6 @@
         raise NotImplementedError("Tried to delete immutable movement %s" % \
             movement.getRelativeUrl())
 
-    return (add_list, modify_dict, delete_list)
-
-  def _getCompensatedMovementList(self, applied_rule,
-                                  matching_property_list=None, **kw):
-    """
-    Compute the difference between prevision and existing movements
-
-    immutable movements need compensation, mutables needs to be modified
-
-    XXX For now, this implementation is too simple. It could be improved by
-    using MovementGroups
-    """
-    if self._isBPM():
-      return self._getCompensatedMovementListBPM(applied_rule, **kw)
-    add_list = [] # list of movements to be added
-    modify_dict = {} # dict of movements to be modified
-    delete_list = [] # list of movements to be deleted
-
-    prevision_list = self._generatePrevisionList(applied_rule, **kw)
-    immutable_movement_list, mutable_movement_list, \
-        deletable_movement_list = self._getCurrentMovementList(applied_rule,
-                                                               **kw)
-    movement_list = immutable_movement_list + mutable_movement_list \
-                    + deletable_movement_list
-    non_matched_list = movement_list[:] # list of remaining movements
-
-    if matching_property_list is None:
-      matching_property_list = self.getMatchingPropertyList()
-
-    for prevision in prevision_list:
-      p_matched_list = []
-      for movement in non_matched_list:
-        for prop in matching_property_list:
-          if movement.isPropertyRecorded(prop):
-            movement_value = movement.getRecordedProperty(prop)
-          else:
-            movement_value = movement.getProperty(prop)
-          if prevision.get(prop) != movement_value:
-            break
-        else:
-          p_matched_list.append(movement)
-
-      # XXX hardcoded ...
-#       LOG("Rule, _getCompensatedMovementList", WARNING,
-#           "Hardcoded properties check")
-      # Movements exist, we'll try to make them match the prevision
-      if p_matched_list != []:
-        # Check the quantity
-        m_quantity = 0.0
-        for movement in p_matched_list:
-          if movement.isPropertyRecorded('quantity'):
-            m_quantity += movement.getRecordedProperty('quantity')
-          else:
-            m_quantity += movement.getQuantity()
-        if m_quantity != prevision.get('quantity'):
-          q_diff = prevision.get('quantity') - m_quantity
-          # try to find a movement that can be edited
-          for movement in p_matched_list:
-            if movement in (mutable_movement_list \
-                + deletable_movement_list):
-              # mark as requiring modification
-              prop_dict = modify_dict.setdefault(movement.getId(), {})
-              #prop_dict['quantity'] = movement.getCorrectedQuantity() + \
-              prop_dict['quantity'] = movement.getQuantity() + \
-                  q_diff
-              break
-          # no modifiable movement was found, need to create one
-          else:
-            prevision['quantity'] = q_diff
-            add_list.append(prevision)
-
-        # Check the date
-        for movement in p_matched_list:
-          if movement in (mutable_movement_list \
-              + deletable_movement_list):
-            prop_dict = modify_dict.setdefault(movement.getId(), {})
-            for prop in ('start_date', 'stop_date'):
-              #XXX should be >= 15
-              if movement.isPropertyRecorded(prop):
-                movement_value = movement.getRecordedProperty(prop)
-              else:
-                movement_value = movement.getProperty(prop)
-              if prevision.get(prop) != movement_value:
-                prop_dict[prop] = prevision.get(prop)
-                break
-
-            for k, v in prevision.items():
-              if k not in ('quantity', 'start_date', 'stop_date'):
-                if movement.isPropertyRecorded(k):
-                  movement_value = movement.getRecordedProperty(k)
-                  if isinstance(movement_value, list) and not isinstance(v, list):
-                    try:
-                      movement_value = movement_value[0]
-                    except IndexError:
-                      movement_value = None
-                else:
-                  movement_value = movement.getProperty(k)
-                if v != movement_value:
-                  prop_dict.setdefault(k, v)
-
-        # update movement lists
-        for movement in p_matched_list:
-          non_matched_list.remove(movement)
-
-      # No movement matched, we need to create one
-      else:
-        add_list.append(prevision)
-
-    # delete non matched movements
-    for movement in non_matched_list:
-      if movement in deletable_movement_list:
-        # delete movement
-        delete_list.append(movement.getId())
-      elif movement in mutable_movement_list:
-        # set movement quantity to 0 to make it "void"
-        prop_dict = modify_dict.setdefault(movement.getId(), {})
-        prop_dict['quantity'] = 0.0
-      else:
-        # movement not modifiable, we can decide to create a compensation
-        # with negative quantity
-        raise NotImplementedError(
-                "Can not create a compensation movement for %s" % \
-                movement.getRelativeUrl())
     return (add_list, modify_dict, delete_list)
 
   def _getExpandablePropertyDict(self, applied_rule, movement, business_path=None,




More information about the Erp5-report mailing list