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.
  • Loading branch information
alt-odoo committed Jan 28, 2020
1 parent cc0f6e2 commit 1d19acf3a0a8c2d9dfee5dd7e082ff118760895d
@@ -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
@@ -366,9 +366,10 @@ def open_payment_matching_screen(self):
def _compute_destination_account_id(self):
for payment in self:
if payment.invoice_ids:
payment.destination_account_id = payment.invoice_ids[0].mapped(
'line_ids.account_id').filtered(
lambda account: account.user_type_id.type in ('receivable', 'payable'))[0]
destination_account = payment.invoice_ids.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.'))
payment.destination_account_id = destination_account
elif payment.payment_type == 'transfer':
if not payment.company_id.transfer_account_id.id:
raise UserError(_('There is no Transfer Account defined in the accounting settings. Please define one to be able to confirm this transfer.'))
@@ -60,21 +60,29 @@ 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')
# payment = self.create_payment(invoices)
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)
import pudb; pudb.set_trace()
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')
#payment = self.create_payment(invoices)
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 1d19acf

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