Commit 9aa34428 authored by Guillaume Michon's avatar Guillaume Michon

Massive update to adapt to the target properties removal


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2878 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cd824f4a
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
from Products.ERP5.Tool.SimulationTool import registerDeliverySolver from Products.ERP5.Tool.SimulationTool import registerDeliverySolver
from DeliverySolver import DeliverySolver from DeliverySolver import DeliverySolver
from zLOG import LOG
class Distribute(DeliverySolver): class Distribute(DeliverySolver):
""" """
...@@ -40,30 +41,63 @@ class Distribute(DeliverySolver): ...@@ -40,30 +41,63 @@ class Distribute(DeliverySolver):
Solve a delivery by reducing / increasing each simulation movement Solve a delivery by reducing / increasing each simulation movement
it relates to it relates to
""" """
delivery_line_simulation_quantity = float(movement.getSimulationQuantity()) # Determine the amount to distribute
d_source = movement.getSource()
d_destination = movement.getDestination()
d_source_section = movement.getSourceSection()
d_destination_section = movement.getDestinationSection()
d_start_date = movement.getStartDate()
d_stop_date = movement.getStopDate()
d_resource = movement.getResource()
simulation_movement_list = movement.getDeliveryRelatedValueList()
new_simulation_movement_list = []
to_aggregate_list = []
delivery_line_simulation_quantity = 0
for simulation_movement in simulation_movement_list:
m_source = simulation_movement.getSource()
m_destination = simulation_movement.getDestination()
m_source_section = simulation_movement.getSourceSection()
m_destination_section = simulation_movement.getDestinationSection()
m_start_date = simulation_movement.getStartDate()
m_stop_date = simulation_movement.getStopDate()
m_resource = simulation_movement.getResource()
if m_source != d_source or \
m_destination != d_destination or \
m_source_section != d_source_section or \
m_destination_section != d_destination_section or \
m_start_date != d_start_date or \
m_stop_date != d_stop_date or \
m_resource != d_resource:
# Disconnect the movement if anything else the quantity is changed
to_aggregate_list.append(simulation_movement)
simulation_movement.setDelivery('')
simulation_movement.setProfitQuantity(simulation_movement.getQuantity())
simulation_movement.setDeliveryError(0.)
simulation_movement.immediateReindexObject()
else:
delivery_line_simulation_quantity += float(simulation_movement.getCorrectedQuantity())
new_simulation_movement_list.append(simulation_movement)
delivery_line_quantity = float(movement.getQuantity()) delivery_line_quantity = float(movement.getQuantity())
if delivery_line_simulation_quantity != delivery_line_quantity: to_distribute = delivery_line_quantity - delivery_line_simulation_quantity
if delivery_line_simulation_quantity != 0 : if to_distribute != 0:
# XXXXXXXXXXXXXXXXXXXXXXXXX something special should be done if delivery_line_simulation_quantity == 0 ! if delivery_line_simulation_quantity != 0:
distribute_ratio = delivery_line_quantity / delivery_line_simulation_quantity for m in new_simulation_movement_list:
for s in movement.getDeliveryRelatedValueList(): m_corrected_quantity = m.getCorrectedQuantity()
# Reduce quantity m_quantity = m.getQuantity()
s.setQuantity(s.getQuantity() * distribute_ratio) m._v_previous_quantity = m_quantity
# Change dates distribute_ratio = m_corrected_quantity / delivery_line_simulation_quantity
s.setStartDate(movement.getStartDate()) m.setQuantity(m_quantity + to_distribute * distribute_ratio)
s.setStopDate(movement.getStopDate()) m.setDeliveryError(0.)
s.diverge() # Make sure everyone knows this simulation movement is inconsistent m.immediateReindexObject()
else: else:
delivery_related_value_list = movement.getDeliveryRelatedValueList() if len(new_simulation_movement_list) > 0:
distribute_ratio = float(len(delivery_related_value_list)) to_add_quantity = to_distribute / len(new_simulation_movement_list)
target_quantity = movement.getTargetQuantity() for m in new_simulation_movement_list:
for s in delivery_related_value_list: m._v_previous_quantity = m.getQuantity()
# Define new quantity m.setQuantity(m.getQuantity() + to_add_quantity)
s.setQuantity(target_quantity / distribute_ratio) m.setDeliveryError(0.)
# Change dates m.immediateReindexObject()
s.setStartDate(movement.getStartDate())
s.setStopDate(movement.getStopDate())
s.diverge() # Make sure everyone knows this simulation movement is inconsistent
# No need to touch date since it should be defined at the upper level.
registerDeliverySolver(Distribute) registerDeliverySolver(Distribute)
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