[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:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user