Commit c8ddfbd2 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Klaus Wölfel

builder: Update fix supply builder for rounding error

parent 95b48171
......@@ -347,9 +347,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
min_order_in_default_quantity_unit = min_order * order_quantity_unit_default_quantity_unit_conversion_ratio
if max_order:
max_order_in_default_quantity_unit = max_order * order_quantity_unit_default_quantity_unit_conversion_ratio
default_quantity_unit_order_quantity_unit_conversion_ratio = 1 / order_quantity_unit_default_quantity_unit_conversion_ratio
else:
default_quantity_unit_order_quantity_unit_conversion_ratio = 1
order_quantity_unit_default_quantity_unit_conversion_ratio = 1
if flow_quantity_unit_value is not None:
flow_quantity_unit_relative_url = flow_quantity_unit_value.getCategoryRelativeUrl()
......@@ -370,7 +369,6 @@ class BuilderMixin(XMLObject, Amount, Predicate):
def minimalQuantity(quantity, date):
# Initiate variables to match original script from Yusei T.
# XXX To be cleaned
conversion_ratio = default_quantity_unit_order_quantity_unit_conversion_ratio
delay_second = max_delay_second or min_delay_second or 0
limit_date = getPreviousValidDate(date)
......@@ -381,8 +379,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
order_delay_second = max_order_delay_second or min_order_delay_second or 0
effective_date = addToDate(start_date, second=-order_delay_second)
order_quantity = ceil(quantity * conversion_ratio)
quantity = order_quantity / conversion_ratio
order_quantity = ceil(quantity / order_quantity_unit_default_quantity_unit_conversion_ratio)
quantity = order_quantity * order_quantity_unit_default_quantity_unit_conversion_ratio
return order_quantity, order_quantity_unit_value, effective_date, start_date, stop_date, quantity
......@@ -500,7 +498,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
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:
if factor and next_next_period_start_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))
......@@ -543,7 +541,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
#self.log("at %s min: %s, inventory:%s, quantity:%s" % (period_start_date, min_inventory, future_inventory_to_date, quantity))
if quantity != 0:
self.log("Week %s Will order %s at %s for period %s" % (delivery_date.week(), quantity, delivery_date, period_start_date))
self.log("Week %s Will order %r at %s for period %s" % (delivery_date.week(), quantity, delivery_date, period_start_date))
movement_list.append(
newMovement(
effective_date,
......
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