From e0182d9ecbc8ab012ffd8e5a55bcc19fef1ccd92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 26 Jan 2023 15:01:10 +0100 Subject: [PATCH] Do not allow to create line or tax on invoice not in draft Adding new line or tax should also be forbidden for validated state. --- modules/account_invoice/invoice.py | 26 +++++++++++--------------- modules/account_invoice/message.xml | 6 +++--- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/modules/account_invoice/invoice.py b/modules/account_invoice/invoice.py index 301a74aeb5..4e6c2ee226 100644 --- a/modules/account_invoice/invoice.py +++ b/modules/account_invoice/invoice.py @@ -2561,13 +2561,11 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin): @classmethod def create(cls, vlist): - Invoice = Pool().get('account.invoice') - invoice_ids = [] - for vals in vlist: - if vals.get('invoice'): - invoice_ids.append(vals.get('invoice')) - for invoice in Invoice.browse(invoice_ids): - if invoice.state in ('posted', 'paid', 'cancelled'): + pool = Pool() + Invoice = pool.get('account.invoice') + invoice_ids = filter(None, {v.get('invoice') for v in vlist}) + for invoice in Invoice.browse(list(invoice_ids)): + if invoice.state != 'draft': raise AccessError( gettext('account_invoice.msg_invoice_line_create', invoice=invoice.rec_name)) @@ -2904,15 +2902,13 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView): @classmethod def create(cls, vlist): - Invoice = Pool().get('account.invoice') - invoice_ids = [] - for vals in vlist: - if vals.get('invoice'): - invoice_ids.append(vals['invoice']) - for invoice in Invoice.browse(invoice_ids): - if invoice.state in ('posted', 'paid', 'cancelled'): + pool = Pool() + Invoice = pool.get('account.invoice') + invoice_ids = filter(None, {v.get('invoice') for v in vlist}) + for invoice in Invoice.browse(list(invoice_ids)): + if invoice.state != 'draft': raise AccessError( - gettext('account_invoice.msg_invoice_tax_create', + gettext('account_invoice.msg_invoice_tax_create_draft', invoice=invoice.rec_name)) return super(InvoiceTax, cls).create(vlist) diff --git a/modules/account_invoice/message.xml b/modules/account_invoice/message.xml index ec98e0130e..54b5574915 100644 --- a/modules/account_invoice/message.xml +++ b/modules/account_invoice/message.xml @@ -51,14 +51,14 @@ this repository contains the full copyright notices and license terms. --> You cannot modify line "%(line)s" because its invoice "%(invoice)s" is posted, paid or cancelled. - - You cannot add a line to invoice "%(invoice)s" because it is posted, paid or cancelled. + + You cannot add lines to invoice "%(invoice)s" because it is no longer in a draft state. You cannot modify tax "%(tax)s" because its invoice "%(invoice)s" is posted, paid or cancelled. - You cannot add a tax to invoice "%(invoice)s" because it is posted, paid or cancelled. + You cannot add taxes to invoice "%(invoice)s" because it is no longer in a draft state. A tax can be added only once to an invoice line.