[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
This commit is contained in:
Lucas Perais (lpe)
2019-01-24 08:49:23 +00:00
parent 15e2857cf3
commit e8803e91e2
2 changed files with 40 additions and 1 deletions
+6 -1
View File
@@ -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.
+34
View File
@@ -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)