From f3b8a9dcd348550a765f25a964eca30ed0a7f068 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 --- 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 02d7a505d5..f9a5f948ac 100644 --- a/modules/account_invoice_history/account.py +++ b/modules/account_invoice_history/account.py @@ -64,10 +64,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]