#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

@ -53,14 +53,24 @@ class AccountMove(models.Model):
return res
def _get_membership_payment_date(self, invoice):
"""Get the date of the most recent reconciled payment.
"""Get the date of the most recent payment reconciled with the invoice.
If there are no payments (e.g. zero-amount invoice), fallback to today.
Uses the ``_get_reconciled_payments()`` helper instead of the
``reconciled_payment_ids`` field: that field was dropped in 18.0 and
only reintroduced on 2025-10-13 (odoo/odoo d8e7798d2c), so it is
missing on older 18.0 builds. ``matched_payment_ids`` is not an option
either: the register wizard links it *after* reconciling, so it is
still empty when ``_invoice_paid_hook`` runs.
If nothing is reconciled (e.g. zero-amount invoice), fallback to today.
"""
self.ensure_one()
payments = invoice.reconciled_payment_ids
payments = invoice._get_reconciled_payments()
if payments:
return max(payments.mapped("date"))
# Counterparts that are not payments: credit notes, manual entries...
reconciled_amls = invoice._get_reconciled_amls()
if reconciled_amls:
return max(reconciled_amls.mapped("date"))
return fields.Date.today()
def _compute_membership_dates(