Commit 19304ac2 authored by Łukasz Nowak's avatar Łukasz Nowak

- move expand to base class


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28145 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7b92c2f8
......@@ -65,25 +65,3 @@ class BPMDeliveryRule(BPMRule):
'delivery_ratio': 1,
'deliverable': 1,
}
security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule, force=0, **kw):
add_list, modify_dict, \
delete_list = self._getCompensatedMovementList(applied_rule, **kw)
# delete not needed movements
for movement_id in delete_list:
applied_rule._delObject(movement_id)
# update existing
for movement, property_dict in modify_dict.items():
applied_rule[movement].edit(**property_dict)
# add new ones
for movement_dict in add_list:
movement_id = applied_rule._get_id(movement_dict.pop('id', None))
new_movement = applied_rule.newContent(id=movement_id,
portal_type=self.movement_type, **movement_dict)
# Pass to base class
BPMRule.expand(self, applied_rule, force=force, **kw) # Simulation workflow
......@@ -67,43 +67,9 @@ class BPMInvoicingRule(BPMRule):
'deliverable': 1
}
security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule, force=0, **kw):
"""
Expands the rule:
- generate a list of previsions
- compare the prevision with existing children
- get the list of existing movements (immutable, mutable, deletable)
- compute the difference between prevision and existing (add,
modify, remove)
- add/modify/remove child movements to match prevision
"""
parent_movement = applied_rule.getParentValue()
if parent_movement is not None:
add_list, modify_dict, \
delete_list = self._getCompensatedMovementList(applied_rule, **kw)
for movement_id in delete_list:
applied_rule._delObject(movement_id)
for movement, prop_dict in modify_dict.items():
applied_rule[movement].edit(**prop_dict)
for movement_dict in add_list:
if 'id' in movement_dict.keys():
mvmt_id = applied_rule._get_id(movement_dict.pop('id'))
new_mvmt = applied_rule.newContent(id=mvmt_id,
portal_type=self.movement_type)
else:
new_mvmt = applied_rule.newContent(portal_type=self.movement_type)
new_mvmt.edit(**movement_dict)
# Pass to base class
BPMRule.expand(self, applied_rule, force=force, **kw)
def _getInputMovementList(self, applied_rule):
"""Returns list of input movements for applied rule"""
return [applied_rule.getParentValue()]
def isDeliverable(self, movement):
return movement.getResource() is not None
......@@ -274,3 +274,25 @@ class BPMRule(Rule):
prevision_dict_list.append(self._getExpandablePropertyDict(applied_rule,
input_movement, business_path))
return prevision_dict_list
security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule, force=0, **kw):
add_list, modify_dict, \
delete_list = self._getCompensatedMovementList(applied_rule, **kw)
# delete not needed movements
for movement_id in delete_list:
applied_rule._delObject(movement_id)
# update existing
for movement, property_dict in modify_dict.items():
applied_rule[movement].edit(**property_dict)
# add new ones
for movement_dict in add_list:
movement_id = applied_rule._get_id(movement_dict.pop('id', None))
new_movement = applied_rule.newContent(id=movement_id,
portal_type=self.movement_type, **movement_dict)
# Pass to base class
Rule.expand(self, applied_rule, force=force, **kw) # Simulation workflow
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