[ADD] account: prevent users to validate invoices/bills/refunds with negative total amount

This commit is contained in:
Laurent Smet
2017-03-21 12:29:18 +01:00
parent 95ace9dafa
commit c8ab32348a
+2
View File
@@ -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()