Commit c2e2dd04 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

buildermixin: Stock optimization can now check intermediate negative stocks

parent fb6e303d
...@@ -168,7 +168,10 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -168,7 +168,10 @@ class BuilderMixin(XMLObject, Amount, Predicate):
delivery_module = getattr(self.getPortalObject(), self.getDeliveryModule()) delivery_module = getattr(self.getPortalObject(), self.getDeliveryModule())
getattr(delivery_module, delivery_module_before_building_script_id)() getattr(delivery_module, delivery_module_before_building_script_id)()
def generateMovementListForStockOptimisation(self, group_by_node=1, **kw): def generateMovementListForStockOptimisation(self, group_by_node=1,
allow_intermediate_negative_stock=True,
**kw):
from Products.ERP5Type.Document import newTempMovement
now = DateTime() now = DateTime()
movement_list = [] movement_list = []
for attribute, method in [('node_uid', 'getDestinationUid'), for attribute, method in [('node_uid', 'getDestinationUid'),
...@@ -232,22 +235,32 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -232,22 +235,32 @@ class BuilderMixin(XMLObject, Amount, Predicate):
min_flow = resource.getProperty(supply_prefix + '_supply_line_min_flow', 0) min_flow = resource.getProperty(supply_prefix + '_supply_line_min_flow', 0)
max_delay = resource.getProperty(supply_prefix + '_supply_line_max_delay', 0) max_delay = resource.getProperty(supply_prefix + '_supply_line_max_delay', 0)
min_stock = resource.getProperty(supply_prefix + '_supply_line_min_stock', 0) min_stock = resource.getProperty(supply_prefix + '_supply_line_min_stock', 0)
if round(inventory_item.inventory, 5) < min_stock: if round(inventory_item.inventory, 5) < min_stock\
or allow_intermediate_negative_stock == False:
stop_date = resource.getNextAlertInventoryDate( stop_date = resource.getNextAlertInventoryDate(
reference_quantity=min_stock, reference_quantity=min_stock,
variation_text=inventory_item.variation_text, variation_text=inventory_item.variation_text,
from_date=now, from_date=now,
group_by_node=group_by_node, group_by_node=group_by_node,
look_for_minimal=not allow_intermediate_negative_stock,
**kw) **kw)
if stop_date is None: if stop_date is None:
stop_date = now stop_date = now
movement = newMovement(inventory_item, resource) min_inventory = resource.getFutureInventory(
movement.edit( variation_text=inventory_item.variation_text,
start_date=stop_date-max_delay, at_date=stop_date,
stop_date=stop_date, **kw
quantity=max(min_flow, -inventory_item.inventory), )
) quantity = max(min_flow, -min_inventory)
movement_list.append(movement) # No need to create a movement with quantity == 0
if quantity != 0:
movement = newMovement(inventory_item, resource)
movement.edit(
start_date=stop_date-max_delay,
stop_date=stop_date,
quantity=quantity,
)
movement_list.append(movement)
# We could need to cancel automated stock optimization if for some reasons # We could need to cancel automated stock optimization if for some reasons
# previous optimisations are obsolete # previous optimisations are obsolete
elif round(inventory_item.inventory, 5) > min_stock: elif round(inventory_item.inventory, 5) > min_stock:
......
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