From 7da73ccebfaeceed23052cc1c032caf772d7cf2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 3 Feb 2021 21:21:03 +0100 Subject: [PATCH] Update unit price after invoice posted and move done issue9962 review292991002 --- CHANGELOG | 2 ++ account.py | 12 ++++++++++++ stock.py | 11 +++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index d7a74e83d8..c284a10c96 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 --git a/account.py b/account.py index 8641bc2f42..7ad19c14bf 100644 --- a/account.py +++ b/account.py @@ -57,6 +57,11 @@ class InvoiceLine(metaclass=PoolMeta): }, 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' @@ -69,6 +74,13 @@ class InvoiceLine(metaclass=PoolMeta): stock_move.uom, stock_move.quantity, self.unit) 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: diff --git a/stock.py b/stock.py index 31ca8c36e7..7917d1cffc 100644 --- a/stock.py +++ b/stock.py @@ -29,6 +29,11 @@ class Move(metaclass=PoolMeta): fields.MultiSelection('get_invoice_types', "Invoice Types"), '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() @@ -75,6 +80,12 @@ class Move(metaclass=PoolMeta): super().do(moves) 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: