From c8ab32348a5596713fbb490fc44117042fd932ba Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Tue, 21 Mar 2017 12:29:18 +0100 Subject: [PATCH] [ADD] account: prevent users to validate invoices/bills/refunds with negative total amount --- addons/account/models/account_invoice.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 3dfe2416616..e5afb8f9bdc 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -573,6 +573,8 @@ class AccountInvoice(models.Model): to_open_invoices = self.filtered(lambda inv: inv.state != 'open') if to_open_invoices.filtered(lambda inv: inv.state != 'draft'): raise UserError(_("Invoice must be in draft state in order to validate it.")) + if to_open_invoices.filtered(lambda inv: inv.amount_total < 0): + raise UserError(_("You cannot validate an invoice with a negative total amount. You should create a refund instead.")) to_open_invoices.action_date_assign() to_open_invoices.action_move_create() return to_open_invoices.invoice_validate()