From e8803e91e22ace82f2ff8712e5c81c8c68ad3930 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 23 Jan 2019 09:51:32 +0000 Subject: [PATCH] [FIX] account: register payment multi invoices In the invoice list view, select one or more invoices click on the action > register payment In the wizard, put an amount inferior to the sum of invoices amount Do a write off Before this commit, the write off was ignored and the invoices not marked as paid After this commit, the write is written, and the invoices marked as paid OPW 1920839 closes odoo/odoo#30465 --- addons/account/models/account_payment.py | 7 ++++- addons/account/tests/test_payment.py | 34 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 48bd0c7ddc9..4c5fc10f637 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -324,7 +324,7 @@ class account_register_payments(models.TransientModel): pmt_communication = self.show_communication_field and self.communication \ or self.group_invoices and ' '.join([inv.reference or inv.number for inv in invoices]) \ or invoices[0].reference # in this case, invoices contains only one element, since group_invoices is False - return { + values = { 'journal_id': self.journal_id.id, 'payment_method_id': self.payment_method_id.id, 'payment_date': self.payment_date, @@ -337,8 +337,13 @@ class account_register_payments(models.TransientModel): 'partner_type': MAP_INVOICE_TYPE_PARTNER_TYPE[invoices[0].type], 'partner_bank_account_id': bank_account.id, 'multi': False, + 'payment_difference_handling': self.payment_difference_handling, + 'writeoff_account_id': self.writeoff_account_id.id, + 'writeoff_label': self.writeoff_label, } + return values + @api.multi def get_payments_vals(self): '''Compute the values for payments. diff --git a/addons/account/tests/test_payment.py b/addons/account/tests/test_payment.py index a061f0c7964..c010d0084aa 100644 --- a/addons/account/tests/test_payment.py +++ b/addons/account/tests/test_payment.py @@ -595,3 +595,37 @@ class TestPayment(AccountingTestCase): # The invoice should now be paid self.assertEqual(invoice.state, 'paid', "Invoice should be in 'paid' state after having reconciled the two payments with a bank statement") + + def test_register_payments_multi_invoices(self): + inv1 = self.create_invoice(amount=40) + inv2 = inv1.copy() + inv2.action_invoice_open() + + batch_payment = self.env['account.register.payments'].with_context(active_ids=(inv1 + inv2).ids).create({ + 'amount': 70, + 'partner_id': inv1.partner_id.id, + 'journal_id': self.bank_journal_usd.id, + 'invoice_ids': [(6, False, (inv1 + inv2).ids)], + 'partner_type': 'customer', + 'payment_difference_handling': 'reconcile', + 'payment_type': 'inbound', + 'payment_method_id': self.payment_method_manual_in.id, + 'writeoff_account_id': self.account_revenue.id, + 'writeoff_label': "why can't we live together"}) + + payment_id = batch_payment.create_payments()['res_id'] + payment_id = self.env['account.payment'].browse(payment_id) + + self.assertEqual(inv1.state, 'paid') + self.assertEqual(inv2.state, 'paid') + + receivable_inv1 = inv1.move_id.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable') + receivable_inv2 = inv2.move_id.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable') + receivable_payment = payment_id.move_line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable') + + self.assertEqual( + receivable_inv1.full_reconcile_id.reconciled_line_ids, + receivable_inv1 + receivable_inv2 + receivable_payment + ) + write_off_line = payment_id.move_line_ids.filtered(lambda l: l.account_id == payment_id.writeoff_account_id) + self.assertEqual(write_off_line.debit, 10)