Commit 537e82c1 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Added handling of distribute in the case of 0.0 quantity


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@113 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9dbe6501
...@@ -42,7 +42,8 @@ class Distribute(DeliverySolver): ...@@ -42,7 +42,8 @@ class Distribute(DeliverySolver):
""" """
delivery_line_quantity = float(movement.getQuantity()) delivery_line_quantity = float(movement.getQuantity())
delivery_line_target_quantity = float(movement.getTargetQuantity()) delivery_line_target_quantity = float(movement.getTargetQuantity())
if delivery_line_quantity != delivery_line_target_quantity and delivery_line_quantity != 0 : if delivery_line_quantity != delivery_line_target_quantity:
if delivery_line_quantity != 0 :
# XXXXXXXXXXXXXXXXXXXXXXXXX something special should be done if delivery_line_quantity == 0 ! # XXXXXXXXXXXXXXXXXXXXXXXXX something special should be done if delivery_line_quantity == 0 !
distribute_ratio = delivery_line_target_quantity / delivery_line_quantity distribute_ratio = delivery_line_target_quantity / delivery_line_quantity
for s in movement.getDeliveryRelatedValueList(): for s in movement.getDeliveryRelatedValueList():
...@@ -52,6 +53,17 @@ class Distribute(DeliverySolver): ...@@ -52,6 +53,17 @@ class Distribute(DeliverySolver):
s.setStartDate(movement.getStartDate()) s.setStartDate(movement.getStartDate())
s.setStopDate(movement.getStopDate()) s.setStopDate(movement.getStopDate())
s.diverge() # Make sure everyone knows this simulation movement is inconsistent s.diverge() # Make sure everyone knows this simulation movement is inconsistent
else:
delivery_related_value_list = movement.getDeliveryRelatedValueList()
distribute_ratio = float(len(delivery_related_value_list))
target_quantity = movement.getTargetQuantity()
for s in delivery_related_value_list:
# Define new quantity
s.setQuantity(target_quantity / distribute_ratio)
# Change dates
s.setStartDate(movement.getStartDate())
s.setStopDate(movement.getStopDate())
s.diverge() # Make sure everyone knows this simulation movement is inconsistent
movement.setQuantity(movement.getTargetQuantity()) movement.setQuantity(movement.getTargetQuantity())
# No need to touch date since it should be defined at the upper level. # No need to touch date since it should be defined at the upper level.
......
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