Commit 070da6a4 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Titouan Soulard

builder: Reach workable calculation

parent bd8f725b
......@@ -461,7 +461,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
)
# Prepare period_list
limit_date = getPreviousValidDate(from_date)
limit_date = getPreviousValidDate(getPreviousValidDate(from_date) - 0.1)
limit_date_list = []
last_date = getPreviousValidDate(history_list[-1][0])
while limit_date <= last_date:
......@@ -471,6 +471,9 @@ class BuilderMixin(XMLObject, Amount, Predicate):
# Hackish and dangerous
next_start_date=limit_date)).earliestTime()
min_stock_value = supply.getMinOrderQuantity() / default_quantity_unit_flow_quantity_unit_conversion_ratio
factor = supply.getMinFlow()
next_period_history_list = []
#self.log(limit_date_list)
# Create a movement per period
for period_start_date in limit_date_list:
......@@ -481,16 +484,46 @@ class BuilderMixin(XMLObject, Amount, Predicate):
next_start_date=period_start_date)).earliestTime()
period_history_list = []
if next_period_history_list and\
next_next_period_start_date == next_period_start_date:
period_history_list = next_period_history_list[:]
while history_list and history_list[0][0] < next_period_start_date:
period_history_list.append(history_list.pop(0))
# Using period history list calculate min stock
min_inventory = self.Base_evaluateMinInventoryForSupplyAtDate(
# In this iteration we verify that the invetory is always superior
# to the min_stock_value
min_inventory_end_of_period = min_stock_value
# Anticipate next period need if a ratio is defined
next_period_history_list = []
next_next_period_start_date = DateTime(supply.getNextPeriodicalDate(
next_period_start_date,
next_start_date=next_period_start_date)).earliestTime()
if factor and next_next_period_start_date <= last_date:
# prepare new hixtory_list
while history_list and history_list[0][0] < next_next_period_start_date:
next_period_history_list.append(history_list.pop(0))
# Calculate need with ratio
# Here it is actually just a ratio of the next period consumption.
min_inventory_end_of_period = self.Base_evaluateMinInventoryForSupplyAtDate(
supply=supply,
history_list=next_period_history_list,
at_date=next_period_start_date,
factor=factor,
min_stock_value=min_inventory_end_of_period,
)
week_consumption = self.Base_evaluateMinInventoryForSupplyAtDate(
supply=supply,
history_list=period_history_list,
at_date=period_start_date,
conversion_ratio=default_quantity_unit_flow_quantity_unit_conversion_ratio,
factor=1,
)
min_inventory = min_inventory_end_of_period + week_consumption
quantity = 0
if future_inventory_to_date < min_inventory: # SKU
......
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