diff --git a/product/ERP5/Document/TradeCondition.py b/product/ERP5/Document/TradeCondition.py index 21579443e924009ceedbb7df6d13eaf8a0bf808d..2d293c1bd5cd8a0a5e125fb6a3a17ebeb8f7a3b4 100644 --- a/product/ERP5/Document/TradeCondition.py +++ b/product/ERP5/Document/TradeCondition.py @@ -222,23 +222,22 @@ class TradeCondition(Path, Transformation, XMLMatrix): # 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): diff --git a/product/ERP5/Document/TradeModelLine.py b/product/ERP5/Document/TradeModelLine.py index 63d96949156b70d156de54a53d58af395573e49b..2177f0a372d9e6f8453eda8ac4156ca85e74c13d 100644 --- a/product/ERP5/Document/TradeModelLine.py +++ b/product/ERP5/Document/TradeModelLine.py @@ -33,7 +33,6 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces 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 @@ class TradeModelLine(Predicate, XMLMatrix, Amount): 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 @@ class TradeModelLine(Predicate, XMLMatrix, Amount): 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 @@ class TradeModelLine(Predicate, XMLMatrix, Amount): 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