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,16 +42,28 @@ class Distribute(DeliverySolver): ...@@ -42,16 +42,28 @@ 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:
# XXXXXXXXXXXXXXXXXXXXXXXXX something special should be done if delivery_line_quantity == 0 ! if delivery_line_quantity != 0 :
distribute_ratio = delivery_line_target_quantity / delivery_line_quantity # XXXXXXXXXXXXXXXXXXXXXXXXX something special should be done if delivery_line_quantity == 0 !
for s in movement.getDeliveryRelatedValueList(): distribute_ratio = delivery_line_target_quantity / delivery_line_quantity
# Reduce quantity for s in movement.getDeliveryRelatedValueList():
s.setQuantity(s.getQuantity() * distribute_ratio) # Reduce quantity
# Change dates s.setQuantity(s.getQuantity() * distribute_ratio)
s.setStartDate(movement.getStartDate()) # Change dates
s.setStopDate(movement.getStopDate()) s.setStartDate(movement.getStartDate())
s.diverge() # Make sure everyone knows this simulation movement is inconsistent s.setStopDate(movement.getStopDate())
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