Commit eb139f87 authored by Romain Courteaud's avatar Romain Courteaud

Recursively solve the simulation tree.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4478 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2574dd3f
...@@ -32,17 +32,47 @@ from zLOG import LOG ...@@ -32,17 +32,47 @@ from zLOG import LOG
class CopyToTarget(TargetSolver): class CopyToTarget(TargetSolver):
""" """
Copy values simulation movement as target. This is Copy values simulation movement as target. This is
only acceptable for root movements. The meaning of only acceptable for root movements. The meaning of
this solver of other movements is far from certain. this solver of other movements is far from certain.
""" """
def solve(self, movement): def solve(self, movement):
""" """
Adopt values as new target Adopt values as new target
""" """
# Reduce quantity # Get interesting value
old_quantity = movement.getQuantity()
old_start_date = movement.getStartDate()
old_stop_date = movement.getStopDate()
new_quantity = movement.getDeliveryQuantity() * \
movement.getDeliveryRatio()
new_start_date = movement.getDeliveryStartDateList()[0]
new_stop_date = movement.getDeliveryStopDateList()[0]
# Calculate delta
quantity_ratio = new_quantity / old_quantity
start_date_delta = new_start_date - old_start_date
stop_date_delta = new_stop_date - old_stop_date
# Modify recursively simulation movement
self._recursivelySolve(movement, quantity_ratio=quantity_ratio,
start_date_delta=start_date_delta,
stop_date_delta=stop_date_delta)
def _recursivelySolve(self, movement, quantity_ratio=1, start_date_delta=0,
stop_date_delta=0):
"""
Update value of the current simulation movement, and update his parent
movement.
"""
# Modify quantity, start_date, stop_date
movement.edit( movement.edit(
quantity=movement.getDeliveryQuantity() * movement.getDeliveryRatio(), quantity=movement.getQuantity() * quantity_ratio,
start_date=movement.getDeliveryStartDateList()[0], start_date=movement.getStartDate() + start_date_delta,
stop_date=movement.getDeliveryStopDateList()[0] stop_date=movement.getStopDate() + stop_date_delta,
) )
applied_rule = movement.getParent()
parent_movement = applied_rule.getParent()
if parent_movement.getPortalType() == "Simulation Movement":
# Modify the parent movement
self._recursivelySolve(parent_movement, quantity_ratio=quantity_ratio,
start_date_delta=start_date_delta,
stop_date_delta=stop_date_delta)
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