Commit 68860733 authored by Fabien Morin's avatar Fabien Morin

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


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28024 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent acb9966a
...@@ -222,7 +222,6 @@ class TradeCondition(Path, Transformation, XMLMatrix): ...@@ -222,7 +222,6 @@ class TradeCondition(Path, Transformation, XMLMatrix):
# initialise run then rerun only once, as trade_model_line_composed_list # initialise run then rerun only once, as trade_model_line_composed_list
# is sorted in good way to have simple algorithm # is sorted in good way to have simple algorithm
for pass_type in ['initialise', 'rerun']:
for model_line in trade_model_line_composed_list: for model_line in trade_model_line_composed_list:
result.extend(model_line.getAggregatedAmountList(context, result.extend(model_line.getAggregatedAmountList(context,
movement_list=movement_list, movement_list=movement_list,
...@@ -231,14 +230,14 @@ class TradeCondition(Path, Transformation, XMLMatrix): ...@@ -231,14 +230,14 @@ class TradeCondition(Path, Transformation, XMLMatrix):
movement_list = result # apply model again on generated movements movement_list = result # apply model again on generated movements
# remove movement that should not be created # remove movement that should not be created
movement_list = [] final_movement_list = []
for movement in result: for movement in movement_list:
movement_ref = movement.getReference() movement_ref = movement.getReference()
for model_line in trade_model_line_composed_list: for model_line in trade_model_line_composed_list:
if model_line.getReference() == movement_ref and\ if model_line.getReference() == movement_ref and\
model_line.isCreateLine(): model_line.isCreateLine():
movement_list.append(movement) final_movement_list.append(movement)
return movement_list return final_movement_list
security.declareProtected( Permissions.AccessContentsInformation, 'getCell') security.declareProtected( Permissions.AccessContentsInformation, 'getCell')
def getCell(self, *kw , **kwd): def getCell(self, *kw , **kwd):
......
...@@ -33,7 +33,6 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces ...@@ -33,7 +33,6 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLMatrix import XMLMatrix from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5.Document.Amount import Amount from Products.ERP5.Document.Amount import Amount
from Products.ERP5.Document.Predicate import Predicate from Products.ERP5.Document.Predicate import Predicate
from Products.ERP5Type.Utils import cartesianProduct
from Products.ERP5.AggregatedAmountList import AggregatedAmountList from Products.ERP5.AggregatedAmountList import AggregatedAmountList
import zope.interface import zope.interface
...@@ -129,8 +128,6 @@ class TradeModelLine(Predicate, XMLMatrix, Amount): ...@@ -129,8 +128,6 @@ class TradeModelLine(Predicate, XMLMatrix, Amount):
tmp_movement_list = [q for q in current_aggregated_amount_list \ tmp_movement_list = [q for q in current_aggregated_amount_list \
if q.getReference() == self.getReference()] if q.getReference() == self.getReference()]
if len(tmp_movement_list) > 0: if len(tmp_movement_list) > 0:
tmp_movement_list = tmp_movement_list[:1] # list is needed in case of
# having cells
update = 1 update = 1
else: else:
# get source and destination using Business Process # get source and destination using Business Process
...@@ -195,19 +192,17 @@ class TradeModelLine(Predicate, XMLMatrix, Amount): ...@@ -195,19 +192,17 @@ class TradeModelLine(Predicate, XMLMatrix, Amount):
update = 0 update = 0
base_category_list = self.getVariationBaseCategoryList() base_category_list = self.getVariationBaseCategoryList()
category_list_list = [] # get cells categories cartesian product
for base_cat in base_category_list: cell_key_list = self.getCellKeyList(base_id='movement')
category_list = self.getVariationCategoryList( if len(cell_key_list) > 0:
base_category_list=base_cat) # look for cells
category_list_list.append(category_list) for cell_coordinates in cell_key_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:
cell = self.getCell(base_id=base_id, *cell_coordinates) cell = self.getCell(base_id=base_id, *cell_coordinates)
if cell is None: if cell is None:
raise ValueError("Can't find the cell corresponding to those "+\ raise ValueError("Line '%s' (%s) can't find the cell corresponding"+\
"cells coordinates : %s" % cell_coordinates) " to those cells coordinates : %s" % (self.getTitle(),
self.getRelativeUrl(),
cell_coordinates))
tmp_movement = newTempSimulationMovement(self.getPortalObject(), tmp_movement = newTempSimulationMovement(self.getPortalObject(),
self_id) self_id)
tmp_movement.edit( tmp_movement.edit(
...@@ -232,14 +227,17 @@ class TradeModelLine(Predicate, XMLMatrix, Amount): ...@@ -232,14 +227,17 @@ class TradeModelLine(Predicate, XMLMatrix, Amount):
self.getQuantity(None) is None or \ self.getQuantity(None) is None or \
len(self.getVariationCategoryList()) and \ len(self.getVariationCategoryList()) and \
tmp_movement.getQuantity(None) is None: tmp_movement.getQuantity(None) is None:
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 # if the quantity is not defined, take it by searching all movements
# that used this base_amount # that used this base_amount
for movement in movement_list:
if set(base_application_list)\ if set(base_application_list)\
.intersection(set(movement.getBaseContributionList())) and \ .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(movement.getVariationCategoryList()).intersection( \
set(tmp_movement.getVariationCategoryList())): set(tmp_movement.getVariationCategoryList()))):
# at least one base application is in base contributions and # at least one base application is in base contributions and
# if the movement have no variation category, it's the same as # if the movement have no variation category, it's the same as
# if he have all variation categories # if he have all variation categories
......
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