From f65a0909abe57ece541ae8d42496016328af933f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 2 Jan 2023 13:16:07 +0100 Subject: [PATCH] Compute history datetime only when invoice has been actually posted Relying only on the numbered_at being filled make the posting process use the history data once the number has been set on the invoice. But as the move computation (with the payment term) happens after, they are done using the history data (which maybe corrupted see #11980). Closes #11982 (grafted from cc0283f3af8479724588d515a77b7ced7dd2e6bf) --HG-- branch : 6.0 --- modules/account_invoice_history/account.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/account_invoice_history/account.py b/modules/account_invoice_history/account.py index e556c1bff6..47ebcd66d5 100644 --- a/modules/account_invoice_history/account.py +++ b/modules/account_invoice_history/account.py @@ -70,10 +70,15 @@ class Invoice(metaclass=PoolMeta): Greatest(table.numbered_at, party.create_date, address.create_date, payment_term.create_date), where=reduce_ids(table.id, ids) - & (table.numbered_at != Null))) + & (table.numbered_at != Null) + & (table.state.in_(cls._history_states())))) datetimes.update(cursor) return datetimes + @classmethod + def _history_states(cls): + return ['posted', 'paid', 'cancelled'] + @classmethod def set_number(cls, invoices): numbered = [i for i in invoices if not i.number or not i.numbered_at]