From 2bf177778ccd77f169168f272f7316b3040ca5d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 21 Oct 2023 00:48:14 +0200 Subject: [PATCH] Defer invoice line only once The post method can be called multiple times for an invoice by process but only one deferral is allowed by line. Also the initial draft deferral may be delete in case of mistake so we must not create automatically a new one later. Closes #12567 (grafted from 7c72d42d78d92db1fbe36217d3ba4720bb621521) --HG-- branch : 6.0 --- modules/account_invoice_defer/account.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/account_invoice_defer/account.py b/modules/account_invoice_defer/account.py index 762dc69308..1f0cc47fda 100644 --- a/modules/account_invoice_defer/account.py +++ b/modules/account_invoice_defer/account.py @@ -445,9 +445,11 @@ class Invoice(metaclass=PoolMeta): def _post(cls, invoices): pool = Pool() InvoiceDeferred = pool.get('account.invoice.deferred') + # defer invoices only the first time post is called + invoices_to_defer = [i for i in invoices if not i.move] super()._post(invoices) deferrals = [] - for invoice in invoices: + for invoice in invoices_to_defer: for line in invoice.lines: if line.deferrable and line.defer_from and line.defer_to: deferral = InvoiceDeferred(