changeset b152a5bce138 in modules/stock_quantity_early_planning:6.2 details: https://hg.tryton.org/modules/stock_quantity_early_planning?cmd=changeset&node=b152a5bce138 description: Deduce only the minimal future quantity
We can deduce only the quantity that is always available in the future. issue11013 review381481002 (grafted from df358a8f2ab6e5b40318b61bd2779d70cb7c583f) diffstat: stock.py | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diffs (33 lines): diff -r 23eaaadaa7c9 -r b152a5bce138 stock.py --- a/stock.py Mon Nov 01 17:15:43 2021 +0100 +++ b/stock.py Thu Dec 16 22:11:07 2021 +0100 @@ -311,9 +311,12 @@ ('date', '<=', move.planned_date), ], order=[('date', 'DESC')])) - last_product_quantity, = ( - ProductQuantitiesByWarehouse.search( - [], order=[('date', 'DESC')], limit=1)) + future_product_quantities = ( + ProductQuantitiesByWarehouse.search([ + ('date', '>=', move.planned_date), + ])) + min_future_product_quantity = min( + p.quantity for p in future_product_quantities) earlier_date = move.planned_date if product_quantities: assert product_quantities[0].date == move.planned_date @@ -322,10 +325,10 @@ min_quantity = ( product_quantities[0].quantity + move.internal_quantity) - if last_product_quantity.quantity > 0: + if min_future_product_quantity > 0: # The remaining quantities can be used - min_quantity -= last_product_quantity.quantity - if min_quantity >= 0: + min_quantity -= min_future_product_quantity + if min_quantity > 0: for product_quantity in product_quantities[1:]: if product_quantity.quantity < min_quantity: break