From 86b91064823ca52c7542f5eb275dfe5a8a45ccfc Mon Sep 17 00:00:00 2001 From: alt-odoo Date: Tue, 28 Jan 2020 12:55:31 +0000 Subject: [PATCH] [FIX] account: prevent group payment if multiple receivable/payable accounts When creating a payment, we are expecting only one destination account. However, when grouping payment by customer, it can happen that there are more than one receivable or payable accounts, which can create reconciliation issues afterward. opw-2188632 opw-2166551 closes odoo/odoo#45396 X-original-commit: 779699297b9767438797ae3678eb9da1db0ce609 Signed-off-by: Nicolas Martinelli (nim) Co-authored-by: Jorge Pinna Puissant --- addons/account/i18n/account.pot | 6 ++++++ addons/account/models/account_payment.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 70e005d3ac7..78641a3847c 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -10986,6 +10986,12 @@ msgid "" "either post or delete them." msgstr "" +#. module: account +#: code:addons/account/models/account_payment.py:0 +#, python-format +msgid "There is more than one receivable/payable account in the concerned invoices. You cannot group payments in that case." +msgstr "" + #. module: account #: code:addons/account/models/account_payment.py:0 #, python-format diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 653256e3799..4d92913892c 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -744,6 +744,10 @@ class payment_register(models.TransientModel): raise UserError(_("You can only register at the same time for payment that are all inbound or all outbound")) if any(inv.company_id != invoices[0].company_id for inv in invoices): raise UserError(_("You can only register at the same time for payment that are all from the same company")) + # Check the destination account is the same + destination_account = invoices.line_ids.filtered(lambda line: line.account_internal_type in ('receivable', 'payable')).mapped('account_id') + if len(destination_account) > 1: + raise UserError(_('There is more than one receivable/payable account in the concerned invoices. You cannot group payments in that case.')) if 'invoice_ids' not in rec: rec['invoice_ids'] = [(6, 0, invoices.ids)] if 'journal_id' not in rec: