From efa4f85480cbea1b68454091168bc988bc9c8341 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 16 May 2017 12:42:47 +0200 Subject: [PATCH] [FIX] account: prevent invoice line unlink Nothing prevents the deletion on invoice line at the Python level. Other modules might give access directly to the invoice lines, and make their deletion possible when the invoice is not draft. opw-743154 --- addons/account/i18n/account.pot | 6 ++++++ addons/account/models/account_invoice.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index a5336193698..9357316cf50 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -9467,6 +9467,12 @@ msgstr "" msgid "You can not delete a payment that is already posted" msgstr "" +#. module: account +#: code:addons/account/models/account_invoice.py:1360 +#, python-format +msgid "You can only delete an invoice line if the invoice is in draft state." +msgstr "" + #. module: account #: code:addons/account/models/account_payment.py:128 #, python-format diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index e30108c82be..81540697766 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -1354,6 +1354,12 @@ class AccountInvoiceLine(models.Model): """ pass + @api.multi + def unlink(self): + if self.filtered(lambda r: r.invoice_id and r.invoice_id.state != 'draft'): + raise UserError(_('You can only delete an invoice line if the invoice is in draft state.')) + return super(AccountInvoiceLine, self).unlink() + class AccountInvoiceTax(models.Model): _name = "account.invoice.tax" _description = "Invoice Tax"