Commit b6159852 authored by Jérome Perrin's avatar Jérome Perrin

Use a more robust way than getDeliveryRelatedValue list to check if we have to

create a new simulation branch for a given delivery movement.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28754 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6fc0872d
......@@ -93,7 +93,7 @@ class DeliveryRule(Rule):
# Create or modify movements
for deliv_mvt in delivery_movement_list:
sim_mvt = deliv_mvt.getDeliveryRelatedValue()
sim_mvt = self._getDeliveryRelatedSimulationMovement(deliv_mvt)
if sim_mvt is None:
# create a new deliv_mvt
if deliv_mvt.getParentUid() == deliv_mvt.getExplanationUid():
......@@ -177,6 +177,30 @@ class DeliveryRule(Rule):
# Pass to base class
Rule.expand(self, applied_rule, **kw)
def _getDeliveryRelatedSimulationMovement(self, delivery_movement):
"""Helper method to get the delivery related simulation movement.
This method is more robust than simply calling getDeliveryRelatedValue
which will not work if simulation movements are not indexed.
"""
simulation_movement = delivery_movement.getDeliveryRelatedValue()
if simulation_movement is not None:
return simulation_movement
# simulation movement was not found, maybe simply because it's not indexed
# yet. We'll look in the simulation tree and try to find it anyway before
# creating another simulation movement.
# Try to find the one from trade model rule, which is the most common case
# where we may expand again before indexation of simulation movements is
# finished.
delivery = delivery_movement.getExplanationValue()
for movement in delivery.getMovementList():
related_simulation_movement = movement.getDeliveryRelatedValue()
if related_simulation_movement is not None:
for applied_rule in related_simulation_movement.contentValues():
for simulation_movement in applied_rule.contentValues():
if simulation_movement.getDeliveryValue() == delivery_movement:
return simulation_movement
return None
security.declareProtected(Permissions.ModifyPortalContent, 'solve')
def solve(self, applied_rule, solution_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