Skip to content
Permalink
Browse files

[FIX] account: prevent group payment if multiple receivable/payable a…

…ccounts

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.

NB: some tests in TestPrintCheck were adapted accordingly since they
were creating batch payment for both invoices and refunds, leading to
multiple receivable/payable accounts.

opw-2188632
opw-2166551

Co-authored-by: Jorge Pinna Puissant <jpp@odoo.com>
  • Loading branch information
alt-odoo and jpp-odoo committed Jan 28, 2020
1 parent cc0f6e2 commit 446983d3ebd18a1c0b7ac38f5e3c987389ce4d10
@@ -10869,6 +10869,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
@@ -757,6 +757,10 @@ def default_get(self, fields):
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.mapped('line_ids.account_id').filtered(lambda account: account.user_type_id.type in ('receivable','payable'))
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:
@@ -60,21 +60,26 @@ def test_print_check(self):
invoices = self.env['account.move']
for i in range(0, 15):
invoices |= self.create_invoice(is_refund=(i % 3 == 0))
payment = self.create_payment(invoices)
self.assertEqual(all(payment.mapped('check_amount_in_words')), True, 'The amount in words is not set on all the payments')
self.assertEqual(all(payment.mapped('check_number')), True, 'The check number is not set on all the payments')
debits = invoices.filtered(lambda r: r.type == 'in_invoice')
credits = invoices.filtered(lambda r: r.type == 'out_refund')
payments = self.create_payment(debits) + self.create_payment(credits)
self.assertEqual(all(payments.mapped('check_amount_in_words')), True, 'The amount in words is not set on all the payments')
self.assertEqual(all(payments.mapped('check_number')), True, 'The check number is not set on all the payments')

# Check the data generated for the report
self.env.ref('base.main_company').write({'account_check_printing_multi_stub': True})
report_pages = payment._check_get_pages()
self.assertEqual(len(report_pages), int(math.ceil(len(payment.reconciled_invoice_ids) / INV_LINES_PER_STUB)))
self.env.ref('base.main_company').write({'account_check_printing_multi_stub': False})
report_pages = payment._check_get_pages()
self.assertEqual(len(report_pages), 1)
for payment in payments:
self.env.ref('base.main_company').write({'account_check_printing_multi_stub': True})
report_pages = payment._check_get_pages()
self.assertEqual(len(report_pages), int(math.ceil(len(payment.reconciled_invoice_ids) / INV_LINES_PER_STUB)))
self.env.ref('base.main_company').write({'account_check_printing_multi_stub': False})
report_pages = payment._check_get_pages()
self.assertEqual(len(report_pages), 1)

def test_from_register(self):
invoices = self.env['account.move']
for i in range(0, 3):
invoices |= self.create_invoice(is_refund=(i % 3 == 0))
payment = self.create_payment(invoices)
self.assertEqual(all(payment.mapped('check_amount_in_words')), True, 'The amount in words is not set on all the payments')
debits = invoices.filtered(lambda r: r.type == 'in_invoice')
credits = invoices.filtered(lambda r: r.type == 'out_refund')
payments = self.create_payment(debits) + self.create_payment(credits)
self.assertEqual(all(payments.mapped('check_amount_in_words')), True, 'The amount in words is not set on all the payments')

0 comments on commit 446983d

Please sign in to comment.
You can’t perform that action at this time.