Commit 84ba6558 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

code cleanup.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30433 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0d37521e
...@@ -33,7 +33,8 @@ from DeliverySolver import DeliverySolver ...@@ -33,7 +33,8 @@ from DeliverySolver import DeliverySolver
class FIFO(DeliverySolver): class FIFO(DeliverySolver):
""" """
The FIFO solver reduces deliveted quantity by reducing the quantity of simulation movements from the last order. The FIFO solver reduces deliveted quantity by reducing the quantity of
simulation movements from the last order.
""" """
# Declarative interfaces # Declarative interfaces
...@@ -45,8 +46,8 @@ class FIFO(DeliverySolver): ...@@ -45,8 +46,8 @@ class FIFO(DeliverySolver):
Move this to mixin Move this to mixin
""" """
self.simulation_movement_list = simulation_movement_list self.simulation_movement_list = simulation_movement_list
def getTotalQuantity(): def getTotalQuantity(self):
""" """
Move this to mixin Move this to mixin
""" """
...@@ -59,22 +60,33 @@ class FIFO(DeliverySolver): ...@@ -59,22 +60,33 @@ class FIFO(DeliverySolver):
""" """
""" """
result = [] result = []
def sortByOrderStartDate(a, b); simulation_movement_list = self._getSimulationMovementList()
return cmp(a.getExplainationValue().getStartDate() b.getExplainationValue().getStartDate()) if len(simulation_movement_list):
simulation_movement_list.sort(sortByOrderStartDate) simulation_movement_list.sort(
simulation_movement_list.reverse() key=lambda x:x.getExplainationValue().getStartDate(), reverse=True)
remaining_quantity = self.getTotalQuantity() - new_quantity remaining_quantity = self.getTotalQuantity() - new_quantity
for movement in self.simulation_movement_list: for movement in simulation_movement_list:
if remaining_quantity: if remaining_quantity:
if movement.getQuantity() < remaining_quantity: quantity = movement.getQuantity()
result.append((movement, movement.getQuantity())) if quantity < remaining_quantity:
remaining_quantity -= movement.getQuantity() result.append((movement, quantity))
remaining_quantity -= quantity
movement.setQuantity(0) movement.setQuantity(0)
else: else:
result.append((movement, remaining_quantity)) result.append((movement, remaining_quantity))
movement.setQuantity(movement.getQuantity() - remaining_quantity) movement.setQuantity(quantity - remaining_quantity)
remaining_quantity = 0 remaining_quantity = 0
# Return movement, split_quantity tuples # Return movement, split_quantity tuples
for movement in simulation_movement_list: for movement in simulation_movement_list:
movement.setDeliveryRatio(movement.getQuantity() / new_quantity) movement.setDeliveryRatio(movement.getQuantity() / new_quantity)
return result return result
\ No newline at end of file
def _getSimulationMovementList(self):
"""
Returns a list of simulation movement sorted from the last order.
"""
simulation_movement_list = self.simulation_movement_list[:]
if len(simulation_movement_list):
simulation_movement_list.sort(
key=lambda x:x.getExplainationValue().getStartDate(), reverse=True)
return simulation_movement_list
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