Commit f3987d03 authored by Fabien Morin's avatar Fabien Morin

return a dict containing two lists :

- 'movement_to_delete_list' : the movement that should be deleted
- 'movement_to_add_list' : the movement that should be added.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27027 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7c6d8794
...@@ -70,23 +70,47 @@ class TradeCondition(Path, Transformation): ...@@ -70,23 +70,47 @@ class TradeCondition(Path, Transformation):
def updateAggregatedAmountList(self, context, **kw): def updateAggregatedAmountList(self, context, **kw):
''' '''
updates exisiting movement and returns new if any updates exisiting movement and returns new if any
return a dict of list of movement 'movement_to_add_list' and
'movement_to_delete_list'
''' '''
existing_movement_list = context.getMovementList() existing_movement_list = context.getMovementList()
aggregated_amount_list = self.getAggregatedAmountList(context = context, aggregated_amount_list = self.getAggregatedAmountList(context = context,
**kw) **kw)
modified_resource_list = [] modified_resource_list = []
for amount in aggregated_amount_list: normal_use_list = self.getPortalObject().portal_preferences\
update_kw = {} .getPreferredNormalResourceUseCategoryList()
for p in self.edited_property_list: # check if the existing movements are in aggregated movments
update_kw[p] = amount.getProperty(p) movement_to_delete_list = []
if len(aggregated_amount_list):
for movement in existing_movement_list: for movement in existing_movement_list:
if movement.getProperty('resource') == update_kw['resource'] and\ keep_movement = False
movement.getVariationCategoryList() == \ for amount in aggregated_amount_list:
amount.getVariationCategoryList(): # here we have to check if the movement is a generated one or
movement.edit(**update_kw) # entered by the user. If it has been entered by user, we have to
modified_resource_list.append(update_kw['resource']) # keep it.
return [amount for amount in aggregated_amount_list if # if movement is generated and if not exist, append to delete list
amount.getResource() not in modified_resource_list] # else, break
resource = movement.getResourceValue()
if resource is not None and \
len(set(normal_use_list).intersection(set(resource\
.getUseList()))):
keep_movement = True
break
update_kw = {}
for p in self.edited_property_list:
update_kw[p] = amount.getProperty(p)
if movement.getProperty('resource') == update_kw['resource'] and\
movement.getVariationCategoryList() == \
amount.getVariationCategoryList():
movement.edit(**update_kw)
modified_resource_list.append(update_kw['resource'])
keep_movement = True
if not keep_movement:
movement_to_delete_list.append(movement)
movement_to_add_list = [amount for amount in aggregated_amount_list if
amount.getResource() not in modified_resource_list]
return {'movement_to_delete_list' : movement_to_delete_list,
'movement_to_add_list': movement_to_add_list}
def getTradeModelLineComposedList(self, context=None): def getTradeModelLineComposedList(self, context=None):
"""Returns list of Trade Model Lines using composition """Returns list of Trade Model Lines using composition
......
...@@ -62,7 +62,8 @@ class ITransformation(Interface): ...@@ -62,7 +62,8 @@ class ITransformation(Interface):
**kw - contains implementations specific parameters **kw - contains implementations specific parameters
The method returns movements, which shall be added. The method return a dict of list of movements : 'movement_to_add_list' and
'movement_to_delete_list'.
""" """
pass pass
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