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)