[Erp5-report] r28024 - /erp5/trunk/products/ERP5/Document/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Jul 8 15:33:39 CEST 2009


Author: fabien
Date: Wed Jul  8 15:33:36 2009
New Revision: 28024

URL: http://svn.erp5.org?rev=28024&view=rev
Log:
fix some mistakes, improve code :
- cartesianProduct is not needed : getCellKeyList can do the same thing in a better and cleaner way
- if movements already exists, we don't want to take only the first one, but all movements are needed
- improve error message to display the Line (title and relative_url) and the coordinates of the not found cell. This will make debugging much more easier
- to set quantity on new created movements, we search on movement_list if movements contribute to the current movement applied on, but we need to look also on already processed movements (current_aggregated_amount_list)
- the condition to check if the quantity of the current movement should be updated was wrong, fix it
- in TradeCondition, now one loop turn is enought to make all calculation
- change some variables names that where already used previously to avoid mistakes

Modified:
    erp5/trunk/products/ERP5/Document/TradeCondition.py
    erp5/trunk/products/ERP5/Document/TradeModelLine.py

Modified: erp5/trunk/products/ERP5/Document/TradeCondition.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/TradeCondition.py?rev=28024&r1=28023&r2=28024&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/TradeCondition.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/TradeCondition.py [utf8] Wed Jul  8 15:33:36 2009
@@ -222,23 +222,22 @@
 
       # initialise run then rerun only once, as trade_model_line_composed_list
       # is sorted in good way to have simple algorithm
-      for pass_type in ['initialise', 'rerun']:
-        for model_line in trade_model_line_composed_list:
-          result.extend(model_line.getAggregatedAmountList(context,
-            movement_list=movement_list,
-            current_aggregated_amount_list=result,
-            **kw))
-        movement_list = result # apply model again on generated movements
+      for model_line in trade_model_line_composed_list:
+        result.extend(model_line.getAggregatedAmountList(context,
+          movement_list=movement_list,
+          current_aggregated_amount_list=result,
+          **kw))
+      movement_list = result # apply model again on generated movements
 
       # remove movement that should not be created
-      movement_list = []
-      for movement in result:
+      final_movement_list = []
+      for movement in movement_list:
         movement_ref = movement.getReference()
         for model_line in trade_model_line_composed_list:
           if model_line.getReference() == movement_ref and\
               model_line.isCreateLine():
-            movement_list.append(movement)
-      return movement_list
+            final_movement_list.append(movement)
+      return final_movement_list
 
     security.declareProtected( Permissions.AccessContentsInformation, 'getCell')
     def getCell(self, *kw , **kwd):

Modified: erp5/trunk/products/ERP5/Document/TradeModelLine.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/TradeModelLine.py?rev=28024&r1=28023&r2=28024&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/TradeModelLine.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/TradeModelLine.py [utf8] Wed Jul  8 15:33:36 2009
@@ -33,7 +33,6 @@
 from Products.ERP5Type.XMLMatrix import XMLMatrix
 from Products.ERP5.Document.Amount import Amount
 from Products.ERP5.Document.Predicate import Predicate
-from Products.ERP5Type.Utils import cartesianProduct
 from Products.ERP5.AggregatedAmountList import AggregatedAmountList
 import zope.interface
 
@@ -129,8 +128,6 @@
     tmp_movement_list = [q for q in current_aggregated_amount_list \
         if q.getReference() == self.getReference()]
     if len(tmp_movement_list) > 0:
-      tmp_movement_list = tmp_movement_list[:1] # list is needed in case of
-                                                # having cells
       update = 1
     else:
       # get source and destination using Business Process
@@ -195,19 +192,17 @@
 
       update = 0
       base_category_list = self.getVariationBaseCategoryList()
-      category_list_list = []
-      for base_cat in base_category_list:
-        category_list = self.getVariationCategoryList(
-                                        base_category_list=base_cat)
-        category_list_list.append(category_list)
-      cartesian_product = cartesianProduct(category_list_list)
-      # look for cells if categories are used
-      if len(category_list_list) > 0:
-        for cell_coordinates in cartesian_product:
+      # get cells categories cartesian product
+      cell_key_list = self.getCellKeyList(base_id='movement')
+      if len(cell_key_list) > 0:
+        # look for cells
+        for cell_coordinates in cell_key_list:
           cell = self.getCell(base_id=base_id, *cell_coordinates)
           if cell is None:
-            raise ValueError("Can't find the cell corresponding to those "+\
-                "cells coordinates : %s" % cell_coordinates)
+            raise ValueError("Line '%s' (%s) can't find the cell corresponding"+\
+                " to those cells coordinates : %s" % (self.getTitle(),
+                                                      self.getRelativeUrl(),
+                                                      cell_coordinates))
           tmp_movement = newTempSimulationMovement(self.getPortalObject(),
               self_id)
           tmp_movement.edit(
@@ -232,14 +227,17 @@
           self.getQuantity(None) is None or \
           len(self.getVariationCategoryList()) and \
           tmp_movement.getQuantity(None) is None:
-        # if the quantity is not defined, take it by searching all movements
-        # that used this base_amount
-        for movement in movement_list:
+        for movement in movement_list + current_aggregated_amount_list:
+          # here we need to look on movement_list and also on already processed
+          # movements (current_aggregated_amount_list).
+          # if the quantity is not defined, take it by searching all movements
+          # that used this base_amount
           if set(base_application_list)\
               .intersection(set(movement.getBaseContributionList())) and \
-              len(movement.getVariationCategoryList()) == 0 or \
+              (len(movement.getVariationCategoryList()) == 0 or \
+               len(tmp_movement.getVariationCategoryList()) == 0 or \
               set(movement.getVariationCategoryList()).intersection( \
-              set(tmp_movement.getVariationCategoryList())):
+              set(tmp_movement.getVariationCategoryList()))):
             # at least one base application is in base contributions and
             # if the movement have no variation category, it's the same as
             # if he have all variation categories




More information about the Erp5-report mailing list