changeset 94244fb0952c in modules/stock_forecast:default
details: 
https://hg.tryton.org/modules/stock_forecast?cmd=changeset&node=94244fb0952c
description:
        Do not complete with non consumable and non goods products

        Since changeset 51c840474497, consumable and not goods products are not 
allowed on forecast
        lines.

        issue11653
        review425571006
diffstat:

 forecast.py |  24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diffs (54 lines):

diff -r 8a1b2c40e01b -r 94244fb0952c forecast.py
--- a/forecast.py       Mon May 02 17:02:01 2022 +0200
+++ b/forecast.py       Fri Aug 26 17:51:12 2022 +0200
@@ -517,7 +517,12 @@
 class ForecastCompleteChoose(ModelView):
     'Complete Forecast'
     __name__ = 'stock.forecast.complete.choose'
-    products = fields.Many2Many('product.product', None, None, 'Products')
+    products = fields.Many2Many(
+        'product.product', None, None, "Products",
+        domain=[
+            ('type', '=', 'goods'),
+            ('consumable', '=', False),
+            ])
 
 
 class ForecastComplete(Wizard):
@@ -587,21 +592,18 @@
             prod2line[forecast_line.product.id] = forecast_line
 
         pbl = self._get_product_quantity()
-        product_ids = [x[1] for x in pbl]
-        prod2uom = {}
-        for product in Product.browse(product_ids):
-            prod2uom[product.id] = product.default_uom.id
+        id2product = {p.id: p for p in Product.browse([x[1] for x in pbl])}
 
-        if getattr(self.choose, 'products', None):
-            products = [x.id for x in self.choose.products]
-        else:
-            products = None
+        products = set(getattr(self.choose, 'products', {}))
 
         to_save = []
         for key, qty in pbl.items():
-            _, product = key
+            _, product_id = key
+            product = id2product[product_id]
             if products and product not in products:
                 continue
+            if product.type != 'goods' or product.consumable:
+                continue
             if -qty <= 0:
                 continue
             if product in prod2line:
@@ -610,7 +612,7 @@
                 line = ForecastLine()
             line.product = product
             line.quantity = -qty
-            line.uom = prod2uom[product]
+            line.uom = product.default_uom.id
             line.forecast = forecast
             line.minimal_quantity = min(1, -qty)
             to_save.append(line)

Reply via email to