From b2d2668f857a280656a6e81b0f1ad6042e3c38bf Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Fri, 29 Mar 2019 13:29:16 +0000 Subject: [PATCH] [FIX] account: negative invoices in batch payments Avoid the user to use batch payment with negative invoices (credit notes or refund) and positive invoices (customer invoices and vendor bills). This will create two different payment, one for the negative invoices and one for the positive invoices, it will not partially reconcile them before register the payment. The normal behaviour is to add the negative invoice (outstanding debits of the supplier or the customer credit notes) to the positive invoice (vendor bill or the customer invoice), and after register the payment of the balance. opw-1959687 closes odoo/odoo#32250 Signed-off-by: Lucas Perais (lpe) --- addons/account/i18n/account.pot | 12 ++++++++++++ addons/account/models/account_payment.py | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 8af8a88254a..0bc13348c7e 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -10907,6 +10907,18 @@ msgstr "" msgid "You cannot put/take money in/out for a bank statement which is closed." msgstr "" +#. module: account +#: code:addons/account/models/account_payment.py:99 +#, python-format +msgid "You cannot register payments for customer invoices and credit notes at the same time." +msgstr "" + +#. module: account +#: code:addons/account/models/account_payment.py:96 +#, python-format +msgid "You cannot register payments for vendor bills and supplier refunds at the same time." +msgstr "" + #. module: account #: code:addons/account/models/account.py:644 #, python-format diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index fb2e7d59f30..3b0e8800d6c 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -87,6 +87,16 @@ class account_abstract_payment(models.AbstractModel): # Check all invoices have the same currency if any(inv.currency_id != invoices[0].currency_id for inv in invoices): raise UserError(_("In order to pay multiple invoices at once, they must use the same currency.")) + # Check if, in batch payments, there are not negative invoices and positive invoices + dtype = invoices[0].type + for inv in invoices[1:]: + if inv.type != dtype: + if ((dtype == 'in_refund' and inv.type == 'in_invoice') or + (dtype == 'in_invoice' and inv.type == 'in_refund')): + raise UserError(_("You cannot register payments for vendor bills and supplier refunds at the same time.")) + if ((dtype == 'out_refund' and inv.type == 'out_invoice') or + (dtype == 'out_invoice' and inv.type == 'out_refund')): + raise UserError(_("You cannot register payments for customer invoices and credit notes at the same time.")) # Look if we are mixin multiple commercial_partner or customer invoices with vendor bills multi = any(inv.commercial_partner_id != invoices[0].commercial_partner_id