#4 fix payment registration

This commit is contained in:
Luis 2026-09-21 16:43:45 +02:00
parent 5b2202f7d4
commit 76dc355c6c
2 changed files with 60 additions and 4 deletions

View file

@ -110,6 +110,15 @@ class TestMembershipPaymentDate(common.TransactionCase):
}
)
cls.product_variable = template_variable.product_variant_id
# Plain service, not a membership
template_service = cls.env["product.template"].create(
{
"name": "Consulting Service",
"type": "service",
"list_price": 50.0,
}
)
cls.product_service = template_service.product_variant_id
def _create_invoice(self, product, invoice_date, quantity=1.0):
"""Create and return a draft out_invoice with the given product."""
@ -311,3 +320,40 @@ class TestMembershipPaymentDate(common.TransactionCase):
self._register_payment(invoice, payment_date=date(2026, 5, 10))
self.assertEqual(mline.date_from, date(2026, 5, 10))
self.assertEqual(mline.date_to, date(2026, 12, 31))
def test_09_single_payment_for_several_invoices(self):
"""One payment settling several invoices at once.
The reconciliation calls _invoice_paid_hook with a multi-record
recordset, which used to raise "Expected singleton".
"""
membership_invoice = self._create_invoice(
self.product_fixed, invoice_date=date(2026, 5, 1)
)
mline = self._post_invoice(membership_invoice)[0]
other_invoice = self._create_invoice(
self.product_service, invoice_date=date(2026, 5, 1)
)
other_invoice.action_post()
invoices = membership_invoice | other_invoice
payment_register = (
self.env["account.payment.register"]
.with_context(
active_model="account.move",
active_ids=invoices.ids,
)
.create(
{
"payment_date": date(2026, 5, 10),
"journal_id": self.bank_journal.id,
"group_payment": True,
}
)
)
payment_register._create_payments()
self.assertTrue(
all(inv.payment_state in ("paid", "in_payment") for inv in invoices)
)
# The membership line still gets the payment date, not today's date
self.assertEqual(mline.date_from, date(2026, 5, 10))
self.assertEqual(mline.date_to, date(2026, 12, 31))