From 95ace9dafa17e57eb61e0fed2cdd6d65474e4645 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Tue, 21 Mar 2017 11:58:40 +0100 Subject: [PATCH 1/6] [ADD] account: split out_invoice/out_refund & in_invoice/in_refund views --- addons/account/views/account_invoice_view.xml | 84 ++++++++++++++++++- .../account/wizard/account_invoice_refund.py | 6 +- 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/addons/account/views/account_invoice_view.xml b/addons/account/views/account_invoice_view.xml index 41f7de14856..b744b050d5e 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,55 @@ + + Customer Refunds + account.invoice + form + tree,kanban,form,calendar,pivot,graph + + [('type','=','out_refund')] + + +

+ Click to create a customer refund. +

+ Odoo's electronic invoicing allows to ease and fasten the + collection of customer payments. Your customer receives the + invoice by email and he can pay online and/or import it + in his own system. +

+ The discussions with your customer are automatically displayed at + the bottom of each invoice. +

+
+
+ + + + 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 +722,44 @@ + + + Vendor Refunds + account.invoice + form + tree,kanban,form,calendar,pivot,graph + + [('type','=','in_refund')] + + +

+ Click to record a new vendor refund. +

+ You can control the invoice from your vendor according to + what you purchased or received. +

+
+
+ + + + tree + + + + + + + form + + + + + + Date: Tue, 21 Mar 2017 12:29:18 +0100 Subject: [PATCH 2/6] [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() From dd6ade733ece4448f4e6be6f31ce1cfd4c767a73 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Tue, 21 Mar 2017 13:18:38 +0100 Subject: [PATCH 3/6] [ADD] account: add warning when adding a line with a negative total amount --- addons/account/models/account_invoice.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index e5afb8f9bdc..ba67838b220 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 @@ -1274,6 +1274,12 @@ class AccountInvoiceLine(models.Model): else: self.price_unit = fix_price(self.product_id.lst_price, taxes, fp_taxes) + @api.onchange('price_subtotal') + def _onchange_price_subtotal(self): + for line in self: + if line.price_subtotal < 0.0: + raise Warning(_('You cannot validate an invoice with a negative total amount. You should create a refund instead.')) + @api.onchange('product_id') def _onchange_product_id(self): domain = {} From a91e9f43ac3959c088cf344d5bafe7d667b387bd Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Wed, 22 Mar 2017 10:12:59 +0100 Subject: [PATCH 4/6] [FIX] account: raise warning when inv amount falls bellow 0 A warning was raised when an invoice line had a negative amount that may cause some trouble when dealing with discount (negative amount). Now, the warning is raised when the amount total of the invoice falls bellow 0. --- addons/account/models/account_invoice.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index ba67838b220..60dc903bce1 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -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 refund instead.')) + @api.model def _default_journal(self): if self._context.get('default_journal_id', False): @@ -1274,12 +1280,6 @@ class AccountInvoiceLine(models.Model): else: self.price_unit = fix_price(self.product_id.lst_price, taxes, fp_taxes) - @api.onchange('price_subtotal') - def _onchange_price_subtotal(self): - for line in self: - if line.price_subtotal < 0.0: - raise Warning(_('You cannot validate an invoice with a negative total amount. You should create a refund instead.')) - @api.onchange('product_id') def _onchange_product_id(self): domain = {} From 5d2ba54be565fc88d650e0b53aa0991f50f9c6cb Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Wed, 22 Mar 2017 10:20:23 +0100 Subject: [PATCH 5/6] [TYPO] account: rename "refund" to "credit note" see opw: 32014 --- addons/account/models/account_invoice.py | 4 ++-- addons/account/views/account_invoice_view.xml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 60dc903bce1..662a3e8828b 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -62,7 +62,7 @@ class AccountInvoice(models.Model): 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 refund instead.')) + 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): @@ -580,7 +580,7 @@ class AccountInvoice(models.Model): 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.")) + 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 b744b050d5e..b313f1dc431 100644 --- a/addons/account/views/account_invoice_view.xml +++ b/addons/account/views/account_invoice_view.xml @@ -646,7 +646,7 @@ - Customer Refunds + Customer Credit Notes account.invoice form tree,kanban,form,calendar,pivot,graph @@ -655,7 +655,7 @@

- Click to create a customer refund. + Click to create a customer credit note.

Odoo's electronic invoicing allows to ease and fasten the collection of customer payments. Your customer receives the @@ -724,7 +724,7 @@ - Vendor Refunds + Vendor Credit Notes account.invoice form tree,kanban,form,calendar,pivot,graph @@ -733,7 +733,7 @@

- Click to record a new vendor refund. + Click to record a new vendor credit note.

You can control the invoice from your vendor according to what you purchased or received. From 2c08370045a7878658f142dffbc2bc6e3be3b4f7 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Wed, 22 Mar 2017 10:41:48 +0100 Subject: [PATCH 6/6] [FIX] account: fix missing default type through context --- addons/account/views/account_invoice_view.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/account/views/account_invoice_view.xml b/addons/account/views/account_invoice_view.xml index b313f1dc431..babb93d9cf5 100644 --- a/addons/account/views/account_invoice_view.xml +++ b/addons/account/views/account_invoice_view.xml @@ -730,6 +730,7 @@ tree,kanban,form,calendar,pivot,graph [('type','=','in_refund')] + {'default_type': 'in_refund', 'journal_type': 'purchase'}