Commit ad5dad5e authored by Guillaume Michon's avatar Guillaume Michon

Use delivery_ratio instead of a saved previous quantity


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3331 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a16fb3e4
...@@ -40,23 +40,18 @@ class ProfitAndLoss(CopyToTarget): ...@@ -40,23 +40,18 @@ class ProfitAndLoss(CopyToTarget):
on the parent applied rule. on the parent applied rule.
""" """
def solve(self, movement, new_target): def solve(self, movement, new_target=None):
""" """
Movement difference as a profit (ie. a quantity coming from nowhere) Movement difference as a profit (ie. a quantity coming from nowhere)
Accumulate into delivered movement Accumulate into delivered movement
""" """
LOG('profit and loss called on movement', 0, repr(movement)) LOG('profit and loss called on movement', 0, repr(movement))
previous_quantity = getattr(movement, '_v_previous_quantity', None) delivery_line = movement.getDeliveryValue()
if previous_quantity is None: delivery_line_quantity = delivery_line.getQuantity()
return if delivery_line_quantity is not None:
added_quantity = movement.getQuantity() - previous_quantity target_quantity = delivery_line_quantity * movement.getDeliveryRatio()
profit_quantity = movement.getProfitQuantity() added_quantity = movement.getQuantity() - target_quantity
if profit_quantity is None: movement.setProfitQuantity(added_quantity)
profit_quantity = 0. movement.immediateReindexObject()
movement.setQuantity(previous_quantity)
movement.setProfitQuantity(profit_quantity - added_quantity)
# The calling method must call Delivery.updateSimulationDeliveryProperties once # The calling method must edit() the delivery to make an automatic workflow converge
# all the movements have been solved
# registerTargetSolver(ProfitAndLoss)
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