diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 908217ae4bc..87c8677d2a0 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -9,7 +9,7 @@ from odoo import api, fields, models, _ from odoo.tools import float_is_zero, float_compare from odoo.tools.misc import formatLang -from odoo.exceptions import UserError, RedirectWarning, ValidationError +from odoo.exceptions import UserError, RedirectWarning, ValidationError, Warning import odoo.addons.decimal_precision as dp import logging @@ -58,6 +58,12 @@ class AccountInvoice(models.Model): self.amount_total_signed = self.amount_total * sign self.amount_untaxed_signed = amount_untaxed_signed * sign + @api.onchange('amount_total') + def _onchange_amount_total(self): + for inv in self: + if inv.amount_total < 0: + raise Warning(_('You cannot validate an invoice with a negative total amount. You should create a credit note instead.')) + @api.model def _default_journal(self): if self._context.get('default_journal_id', False): @@ -573,6 +579,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 credit note instead.")) to_open_invoices.action_date_assign() to_open_invoices.action_move_create() return to_open_invoices.invoice_validate() diff --git a/addons/account/views/account_invoice_view.xml b/addons/account/views/account_invoice_view.xml index 41f7de14856..8cabb8da63f 100644 --- a/addons/account/views/account_invoice_view.xml +++ b/addons/account/views/account_invoice_view.xml @@ -610,7 +610,7 @@ form tree,kanban,form,calendar,pivot,graph - [('type','in',('out_invoice', 'out_refund'))] + [('type','=','out_invoice')] {'type':'out_invoice', 'journal_type': 'sale'} @@ -645,13 +645,51 @@ + + Customer Credit Notes + account.invoice + form + tree,kanban,form,calendar,pivot,graph + + [('type','=','out_refund')] + {'default_type': 'out_refund', 'journal_type': 'sale'} + + + + Click to create a credit note. + + Note that the easiest way to create a credit note is to do it directly form + the customer invoice, to refund it totally or partially. + + + + + + + tree + + + + + + + form + + + + + + Vendor Bills account.invoice form tree,kanban,form,calendar,pivot,graph - [('type','in',('in_invoice', 'in_refund'))] + [('type','=','in_invoice')] {'default_type': 'in_invoice', 'type': 'in_invoice', 'journal_type': 'purchase'} @@ -680,6 +718,42 @@ + + + Vendor Credit Notes + account.invoice + form + tree,kanban,form,calendar,pivot,graph + + [('type','=','in_refund')] + {'default_type': 'in_refund', 'journal_type': 'purchase'} + + + + Click to record a new vendor credit note. + + + + + + + tree + + + + + + + form + + + + + +
+ Click to create a credit note. +
+ Note that the easiest way to create a credit note is to do it directly form + the customer invoice, to refund it totally or partially. +
+ Click to record a new vendor credit note. +