Commit 4e6abb56 authored by Sebastien Robin's avatar Sebastien Robin

inventories: allow to use getNextAlertInventoryDate to know when the stock will be enough

Instead of only having possibility to check when inventory will be below a reference_quantity,
allow to check when it will be higher.
parent 5e05622e
......@@ -2020,19 +2020,32 @@ class SimulationTool(BaseTool):
def getNextAlertInventoryDate(self, reference_quantity=0, src__=0,
simulation_period='Future',from_date=None, **kw):
simulation_period='Future', from_date=None,
range='min', **kw):
Give the next date where the quantity is lower than the
reference quantity.
range - either 'min' (default) or 'nlt'. With 'nlt', returns
the next date where inventory is above reference_quantity
result = None
# First look at current inventory, we might have already an inventory
# lower than reference_quantity
def getCheckQuantityMethod():
if range == 'min':
return lambda x: x < reference_quantity
elif range == 'nlt':
return lambda x: x >= reference_quantity
raise ValueError("Uknown range type : %s" % (range,))
checkQuantity = getCheckQuantityMethod()
if from_date is None:
from_date = DateTime()
inventory_method = getattr(self, "get%sInventory" % simulation_period)
current_inventory = inventory_method(at_date=from_date, **kw)
if current_inventory < reference_quantity:
if checkQuantity(current_inventory):
result = from_date
inventory_list_method = getattr(self,
......@@ -2045,7 +2058,7 @@ class SimulationTool(BaseTool):
for inventory in inventory_list:
if inventory['inventory'] is not None:
total_inventory += inventory['inventory']
if total_inventory < reference_quantity:
if checkQuantity(total_inventory):
result = inventory['date']
return result
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