changeset affac0b0273e in modules/account_invoice_stock:default
details: 
https://hg.tryton.org/modules/account_invoice_stock?cmd=changeset;node=affac0b0273e
description:
        Update unit price after invoice posted and move done

        issue9962
        review292991002
diffstat:

 CHANGELOG  |   2 ++
 account.py |  12 ++++++++++++
 stock.py   |  11 +++++++++++
 3 files changed, 25 insertions(+), 0 deletions(-)

diffs (66 lines):

diff -r bfc3ef0aa3c0 -r affac0b0273e CHANGELOG
--- a/CHANGELOG Sat Dec 19 17:08:44 2020 +0100
+++ b/CHANGELOG Wed Feb 03 21:21:03 2021 +0100
@@ -1,3 +1,5 @@
+* Update unit price after invoice posted and move done
+
 Version 5.8.0 - 2020-11-02
 * Bug fixes (see mercurial logs for details)
 * Remove support for Python 3.5
diff -r bfc3ef0aa3c0 -r affac0b0273e account.py
--- a/account.py        Sat Dec 19 17:08:44 2020 +0100
+++ b/account.py        Wed Feb 03 21:21:03 2021 +0100
@@ -57,6 +57,11 @@
             },
         depends=['type', 'product_uom_category', 'invoice', 'invoice_type'])
 
+    @classmethod
+    def __setup__(cls):
+        super().__setup__()
+        cls._check_modify_exclude.add('stock_moves')
+
     @property
     def moved_quantity(self):
         'The quantity from linked stock moves in line unit'
@@ -70,6 +75,13 @@
         return quantity
 
     @classmethod
+    def write(cls, *args):
+        super().write(*args)
+        lines = sum(args[0:None:2], [])
+        moves = sum((l.stock_moves for l in lines), ())
+        cls.update_unit_price(moves)
+
+    @classmethod
     def copy(cls, lines, default=None):
         if default is None:
             default = {}
diff -r bfc3ef0aa3c0 -r affac0b0273e stock.py
--- a/stock.py  Sat Dec 19 17:08:44 2020 +0100
+++ b/stock.py  Wed Feb 03 21:21:03 2021 +0100
@@ -30,6 +30,11 @@
         'on_change_with_invoice_types')
 
     @classmethod
+    def __setup__(cls):
+        super().__setup__()
+        cls._allow_modify_closed_period.add('invoice_lines')
+
+    @classmethod
     def get_invoice_types(cls):
         pool = Pool()
         Invoice = pool.get('account.invoice')
@@ -76,6 +81,12 @@
         cls.update_unit_price(moves)
 
     @classmethod
+    def write(cls, *args):
+        super().write(*args)
+        moves = sum(args[0:None:2], [])
+        cls.update_unit_price(moves)
+
+    @classmethod
     def update_unit_price(cls, moves):
         for move in moves:
             if move.state == 'done':

Reply via email to