changeset df358a8f2ab6 in modules/stock_quantity_early_planning:default
details: 
https://hg.tryton.org/modules/stock_quantity_early_planning?cmd=changeset&node=df358a8f2ab6
description:
        Deduce only the minimal future quantity

        We can deduce only the quantity that is always available in the future.

        issue11013
        review381481002
diffstat:

 stock.py |  15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diffs (33 lines):

diff -r 4f62bf7f1243 -r df358a8f2ab6 stock.py
--- a/stock.py  Mon Dec 13 23:10:12 2021 +0100
+++ b/stock.py  Thu Dec 16 22:11:07 2021 +0100
@@ -361,9 +361,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
@@ -372,10 +375,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

Reply via email to