changeset db14ed384667 in modules/stock_quantity_early_planning:default
details: 
https://hg.tryton.org/modules/stock_quantity_early_planning?cmd=changeset&node=db14ed384667
description:
        Prevent early planning of production missing moves

        issue11080
        review383891002
diffstat:

 CHANGELOG |   1 +
 stock.py  |  21 ++++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletions(-)

diffs (66 lines):

diff -r 2e8d2dd34224 -r db14ed384667 CHANGELOG
--- a/CHANGELOG Sun Jan 23 12:54:56 2022 +0100
+++ b/CHANGELOG Sun Jan 23 13:34:13 2022 +0100
@@ -1,3 +1,4 @@
+* Prevent early planning of production missing moves
 * Compute early date for partial quantity of stock move
 * Add support for Python 3.10
 * Remove support for Python 3.6
diff -r 2e8d2dd34224 -r db14ed384667 stock.py
--- a/stock.py  Sun Jan 23 12:54:56 2022 +0100
+++ b/stock.py  Sun Jan 23 13:34:13 2022 +0100
@@ -1,5 +1,6 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
+import datetime as dt
 from collections import defaultdict
 from itertools import groupby
 
@@ -130,6 +131,11 @@
     def get_earliest_date(self, name):
         return self._get_dates(min)
 
+    @property
+    def _allow_partial_moves(self):
+        "Allow to early planning without all moves"
+        return True
+
     def _get_dates(self, aggregate):
         pool = Pool()
         Move = pool.get('stock.move')
@@ -139,6 +145,9 @@
                 return self.origin.planned_date
             else:
                 return self.early_date
+        elif (not self._allow_partial_moves
+                and any(not m.early_date for m in self.moves)):
+            return self.planned_date
         else:
             return aggregate(
                 filter(None, (m._get_dates(aggregate) for m in self.moves)),
@@ -163,7 +172,7 @@
             total = sum(m.origin.internal_quantity for m in self.moves)
             quantity = sum(
                 m._early_quantity for m in self.moves
-                if m.early_date and m.early_date <= date)
+                if (m.early_date or m.planned_date or dt.date.max) <= date)
             if total:
                 return round(quantity / total, 4)
             else:
@@ -465,6 +474,16 @@
     def _get_origins(cls):
         return super()._get_origins() + ['production']
 
+    @property
+    def _allow_partial_moves(self):
+        pool = Pool()
+        Production = pool.get('production')
+        allow = super()._allow_partial_moves
+        if (isinstance(self.origin, Production)
+                and any(not m.early_date for m in self.moves)):
+            allow = False
+        return allow
+
     def get_moves(self, name):
         pool = Pool()
         Production = pool.get('production')

Reply via email to