From fb813f5abc40204d57ffe9cfd34e8eb43b5a5178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 24 Oct 2024 00:52:27 +0200 Subject: [PATCH] Set and unset consignment origin without changing the state of the move When changing the state of the move, the workflow transition of the decorated function may filter out the move because the transition does not exist for the new state. Closes #13623 --- modules/stock_consignment/stock.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/stock_consignment/stock.py b/modules/stock_consignment/stock.py index 0dfa607fe9..83ff6f509f 100644 --- a/modules/stock_consignment/stock.py +++ b/modules/stock_consignment/stock.py @@ -73,13 +73,14 @@ def set_origin_consignment(state): if to_save: InvoiceLine.save(to_save) for move, line in move2line.items(): - move.state = state if not move.origin: move.origin = line + original_state, move.state = move.state, state if (move.on_change_with_unit_price_required() and move.unit_price is None): move.unit_price = line.unit_price move.currency = line.currency + move.state = original_state cls.save(list(move2line.keys())) return func(cls, moves) return wrapper @@ -94,7 +95,6 @@ def unset_origin_consignment(state): InvoiceLine = pool.get('account.invoice.line') lines, to_save = [], set() for move in moves: - move.state = state for invoice_line in move.consignment_invoice_lines: lines.append(invoice_line) if move.origin == move: @@ -124,7 +124,8 @@ class Move(metaclass=PoolMeta): 'invisible': ~Eval('consignment_invoice_lines'), }) - @fields.depends('state', 'from_location', 'to_location') + @fields.depends( + 'state', 'from_location', 'to_location', 'unit_price', 'currency') def on_change_with_unit_price_required(self, name=None): required = super().on_change_with_unit_price_required(name) if (required @@ -139,7 +140,9 @@ class Move(metaclass=PoolMeta): 'storage', 'production', 'supplier'} and self.to_location.type == 'customer')) and self.from_location.consignment_party): - required = False + # Keep the requirement to allow origin consignment decorators to + # set the unit price before changing the move state + required = (self.unit_price is not None) and self.currency return required @classmethod