Commit 4c7d805f authored by Fabien Morin's avatar Fabien Morin

make getAggregatedAmountList supporting model_lines with categories containing more than one cell


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27357 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6c73f330
...@@ -29,11 +29,12 @@ ...@@ -29,11 +29,12 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, interfaces 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.Variated import Variated from Products.ERP5.Variated import Variated
from Products.ERP5Type.Utils import cartesianProduct
from Products.ERP5.AggregatedAmountList import AggregatedAmountList from Products.ERP5.AggregatedAmountList import AggregatedAmountList
...@@ -70,8 +71,8 @@ class TradeModelLine(XMLMatrix, Amount, Variated): ...@@ -70,8 +71,8 @@ class TradeModelLine(XMLMatrix, Amount, Variated):
raise NotImplementedError('TODO') raise NotImplementedError('TODO')
def getAggregatedAmountList(self, context, movement_list = None, def getAggregatedAmountList(self, context, movement_list = None,
current_aggregated_amount_list = None, **kw): current_aggregated_amount_list = None, base_id='movement', **kw):
from Products.ERP5Type.Document import newTempMovement from Products.ERP5Type.Document import newTempSimulationMovement
normal_resource_use_category_list = self.\ normal_resource_use_category_list = self.\
portal_preferences.getPreferredNormalResourceUseCategoryList() portal_preferences.getPreferredNormalResourceUseCategoryList()
...@@ -109,36 +110,69 @@ class TradeModelLine(XMLMatrix, Amount, Variated): ...@@ -109,36 +110,69 @@ class TradeModelLine(XMLMatrix, Amount, Variated):
self_id = self.getParentValue().getId() + '_' + self.getId() self_id = self.getParentValue().getId() + '_' + self.getId()
tmp_movement = [q for q in current_aggregated_amount_list \ tmp_movement_list = [q for q in current_aggregated_amount_list \
if q.getProperty('resource') == self.getResource() ] if q.getProperty('resource') == self.getResource() ]
if len(tmp_movement) > 0: if len(tmp_movement_list) > 0:
tmp_movement = tmp_movement[0] tmp_movement_list = tmp_movement_list[:1]
update = 1 update = 1
else: else:
update = 0 update = 0
tmp_movement = newTempMovement(self.getPortalObject(), self_id ) base_category_list = self.getVariationBaseCategoryList()
tmp_movement.edit( category_list_list = []
causality = self.getRelativeUrl(), for base_cat in base_category_list:
resource = self.getResource(), category_list = self.getVariationCategoryList(
base_application_list = base_application_list, base_category_list=base_cat)
base_contribution_list = self.getBaseContributionList(), category_list_list.append(category_list)
price = self.getPrice(), cartesian_product = cartesianProduct(category_list_list)
trade_phase_list = self.getTradePhaseList(), # if categories are used, we want to look for all cells
) if len(category_list_list) > 0:
for cell_coordinates in cartesian_product:
modified = 0 cell = self.getCell(base_id=base_id, *cell_coordinates)
for movement in movement_list: if cell is None:
if set(base_application_list)\ raise ValueError("Can't find the cell corresponding to those "+\
.intersection(set(movement.getBaseContributionList())): "cells coordinates : %s" % cell_coordinates)
quantity = tmp_movement.getQuantity(0.0) tmp_movement = newTempSimulationMovement(self.getPortalObject(),
modified = 1 self_id )
tmp_movement.edit(
variation_base_category_list = cell.getVariationBaseCategoryList(),
variation_category_list = cell.getVariationCategoryList(),
causality = self.getRelativeUrl(),
resource = self.getResource(),
base_application_list = base_application_list,
base_contribution_list = self.getBaseContributionList(),
price = cell.getPrice(),
quantity = cell.getQuantity(0.0),
trade_phase_list = self.getTradePhaseList(),
)
tmp_movement_list.append(tmp_movement)
else:
tmp_movement = newTempSimulationMovement(self.getPortalObject(),
self_id )
tmp_movement.edit( tmp_movement.edit(
quantity = quantity + movement.getTotalPrice() causality = self.getRelativeUrl(),
resource = self.getResource(),
base_application_list = base_application_list,
base_contribution_list = self.getBaseContributionList(),
price = self.getPrice(),
trade_phase_list = self.getTradePhaseList(),
) )
tmp_movement_list.append(tmp_movement)
if not update: modified = 0
if modified:
aggregated_amount_list.append(tmp_movement) for tmp_movement in tmp_movement_list:
for movement in movement_list:
if set(base_application_list)\
.intersection(set(movement.getBaseContributionList())):
quantity = tmp_movement.getQuantity(0.0)
modified = 1
tmp_movement.edit(
quantity = quantity + movement.getTotalPrice()
)
if not update:
if modified:
aggregated_amount_list.append(tmp_movement)
return aggregated_amount_list return aggregated_amount_list
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