Commit 8df209bb authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

implement MinPrice delivery solver.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30444 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a3d47551
...@@ -27,11 +27,52 @@ ...@@ -27,11 +27,52 @@
# #
############################################################################## ##############################################################################
import zope.interface
from Products.ERP5Type import interfaces
from DeliverySolver import DeliverySolver from FIFO import FIFO
class MinPrice(DeliverySolver): class MinPrice(FIFO):
""" """
The MinPrice deliver solver distributes quantity in order to minimise price. The MinPrice deliver solver distributes quantity in order to minimise
price.
""" """
# Declarative interfaces
zope.interface.implements(interfaces.IDeliverySolver)
title = 'MinPrice Solver'
def setTotalQuantity(self, new_quantity):
"""
"""
result = []
simulation_movement_list = self._getSimulationMovementList()
remaining_quantity = self.getTotalQuantity() - new_quantity
if remaining_quantity > 0:
# In case of reducing the quantity, we should start from the more
# expensive price.
simulation_movement_list.reverse()
for movement in simulation_movement_list:
if remaining_quantity:
quantity = movement.getQuantity()
if quantity < remaining_quantity:
result.append((movement, quantity))
remaining_quantity -= quantity
movement.setQuantity(0)
else:
result.append((movement, remaining_quantity))
movement.setQuantity(quantity - remaining_quantity)
remaining_quantity = 0
# Return movement, split_quantity tuples
for movement in simulation_movement_list:
movement.setDeliveryRatio(movement.getQuantity() / new_quantity)
return result
def _getSimulationMovementList(self):
"""
Returns a list of simulation movement sorted from the lower price.
"""
simulation_movement_list = self.simulation_movement_list[:]
if len(simulation_movement_list):
simulation_movement_list.sort(key=lambda x:x.getPrice())
return simulation_movement_list
...@@ -95,7 +95,7 @@ class SolverTool(BaseTool): ...@@ -95,7 +95,7 @@ class SolverTool(BaseTool):
""" """
# XXX Hardcoded for now. We need a new registration system for # XXX Hardcoded for now. We need a new registration system for
# delivery solvers. # delivery solvers.
return ['FIFO', 'FILO',] return ['FIFO', 'FILO', 'MinPrice',]
def getDeliverySolverTranslatedItemList(self, class_name_list=None): def getDeliverySolverTranslatedItemList(self, class_name_list=None):
""" """
......
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