Commit 927bb9ee authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

do not include movements that are already simulated by other rules.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32059 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 29823c3e
......@@ -119,5 +119,36 @@ class DeliveryRuleMovementGenerator(MovementGeneratorMixin):
if delivery is None:
return []
else:
return delivery.getMovementList(
portal_type=delivery.getPortalDeliveryMovementTypeList())
ret = []
existing_movement_list = context.objectValues()
for movement in delivery.getMovementList(
portal_type=delivery.getPortalDeliveryMovementTypeList()):
simulation_movement = self._getDeliveryRelatedSimulationMovement(movement)
if simulation_movement is None or \
simulation_movement in existing_movement_list:
ret.append(movement)
return ret
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
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