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
This commit is contained in:
Cédric Krier committed 2023-01-02 13:16:07 +01:00
1 parent 4ad9e64532
commit f65a0909ab
1 file changed
+6 -1
+6 -1
View File
@@ -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]