Compare commits
4 Commits
e14eafed39
...
568f49c784
| Author | SHA1 | Date | |
|---|---|---|---|
| 568f49c784 | |||
| 54bb9f0788 | |||
| d6b87de53c | |||
| 42676fcdd0 |
30
account_move_last_payment/README.md
Normal file
30
account_move_last_payment/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Account Move Last Payment
|
||||
|
||||
Expose on `account.move` the date of the most recent real payment reconciled with an
|
||||
invoice, as a stored, exportable field shown in the invoice list view.
|
||||
|
||||
## Features
|
||||
|
||||
- `last_payment_date` (Date): date of the most recent payment reconciled with the
|
||||
invoice — partial payments included.
|
||||
- Covers both Community reconciliation paths: explicit payment ("Register Payment"
|
||||
wizard) and direct bank statement reconciliation. Manual reconciliations without
|
||||
payment or statement line are ignored, as are exchange difference moves.
|
||||
- Recomputes automatically on reconcile / unreconcile and when a payment or statement
|
||||
line date changes.
|
||||
- The field is stored and displayed as an optional column of the invoice list view, so
|
||||
it is exportable.
|
||||
|
||||
## Installation
|
||||
|
||||
Depends on the `account` module only.
|
||||
|
||||
## Credits
|
||||
|
||||
### Contributors
|
||||
|
||||
- Elabore - Assisted by AI
|
||||
|
||||
### Maintainer
|
||||
|
||||
- Elabore
|
||||
1
account_move_last_payment/__init__.py
Normal file
1
account_move_last_payment/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
21
account_move_last_payment/__manifest__.py
Normal file
21
account_move_last_payment/__manifest__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Copyright 2026 Elabore
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "Account Move Last Payment",
|
||||
"version": "18.0.1.0.0",
|
||||
"summary": "Last real payment date on invoices",
|
||||
"author": "Elabore",
|
||||
"website": "https://git.elabore.coop/elabore/account-tools",
|
||||
"license": "AGPL-3",
|
||||
"category": "Accounting",
|
||||
"depends": [
|
||||
"account",
|
||||
],
|
||||
"data": [
|
||||
"views/account_move_views.xml",
|
||||
],
|
||||
"installable": True,
|
||||
"auto_install": False,
|
||||
"application": False,
|
||||
}
|
||||
47
account_move_last_payment/i18n/account_move_last_payment.pot
Normal file
47
account_move_last_payment/i18n/account_move_last_payment.pot
Normal file
@@ -0,0 +1,47 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * account_move_last_payment
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 18.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-10-29 10:16+0000\n"
|
||||
"PO-Revision-Date: 2026-10-29 10:16+0000\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: account_move_last_payment
|
||||
#: model:ir.model.fields,help:account_move_last_payment.field_account_bank_statement_line__last_payment_date
|
||||
#: model:ir.model.fields,help:account_move_last_payment.field_account_move__last_payment_date
|
||||
msgid ""
|
||||
"Date of the most recent payment reconciled with this invoice, whatever the "
|
||||
"reconciliation path (explicit payment or direct bank statement line "
|
||||
"reconciliation)."
|
||||
msgstr ""
|
||||
|
||||
#. module: account_move_last_payment
|
||||
#: model:ir.model,name:account_move_last_payment.model_account_move
|
||||
msgid "Journal Entry"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_move_last_payment
|
||||
#: model:ir.model.fields,field_description:account_move_last_payment.field_account_bank_statement_line__last_payment_date
|
||||
#: model:ir.model.fields,field_description:account_move_last_payment.field_account_move__last_payment_date
|
||||
msgid "Last Payment Date"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_move_last_payment
|
||||
#: model:ir.model.fields,field_description:account_move_last_payment.field_account_bank_statement_line__preferred_payment_method_line_id
|
||||
#: model:ir.model.fields,field_description:account_move_last_payment.field_account_move__preferred_payment_method_line_id
|
||||
msgid "Planned Payment Method"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_move_last_payment
|
||||
#: model:ir.model.fields,field_description:account_move_last_payment.field_account_move__smart_search
|
||||
msgid "Smart Search"
|
||||
msgstr ""
|
||||
45
account_move_last_payment/i18n/fr.po
Normal file
45
account_move_last_payment/i18n/fr.po
Normal file
@@ -0,0 +1,45 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * account_move_last_payment
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 18.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-10-29 10:16+0000\n"
|
||||
"PO-Revision-Date: 2026-10-29 10:16+0000\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: account_move_last_payment
|
||||
#: model:ir.model.fields,help:account_move_last_payment.field_account_bank_statement_line__last_payment_date
|
||||
#: model:ir.model.fields,help:account_move_last_payment.field_account_move__last_payment_date
|
||||
msgid ""
|
||||
"Date of the most recent payment reconciled with this invoice, whatever the "
|
||||
"reconciliation path (explicit payment or direct bank statement line "
|
||||
"reconciliation)."
|
||||
msgstr ""
|
||||
"Date du paiement le plus récent lettré avec cette facture, quel que soit "
|
||||
"le chemin de lettrage (paiement explicite ou rapprochement direct d'une "
|
||||
"ligne de relevé bancaire)."
|
||||
|
||||
#. module: account_move_last_payment
|
||||
#: model:ir.model,name:account_move_last_payment.model_account_move
|
||||
msgid "Journal Entry"
|
||||
msgstr "Écriture comptable"
|
||||
|
||||
#. module: account_move_last_payment
|
||||
#: model:ir.model.fields,field_description:account_move_last_payment.field_account_bank_statement_line__last_payment_date
|
||||
#: model:ir.model.fields,field_description:account_move_last_payment.field_account_move__last_payment_date
|
||||
msgid "Last Payment Date"
|
||||
msgstr "Date du dernier paiement"
|
||||
|
||||
#. module: account_move_last_payment
|
||||
#: model:ir.model.fields,field_description:account_move_last_payment.field_account_bank_statement_line__preferred_payment_method_line_id
|
||||
#: model:ir.model.fields,field_description:account_move_last_payment.field_account_move__preferred_payment_method_line_id
|
||||
msgid "Planned Payment Method"
|
||||
msgstr "Mode de paiement"
|
||||
1
account_move_last_payment/models/__init__.py
Normal file
1
account_move_last_payment/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import account_move
|
||||
71
account_move_last_payment/models/account_move.py
Normal file
71
account_move_last_payment/models/account_move.py
Normal file
@@ -0,0 +1,71 @@
|
||||
# Copyright 2026 Elabore
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
last_payment_date = fields.Date(
|
||||
compute="_compute_last_payment_date",
|
||||
store=True,
|
||||
copy=False,
|
||||
help="Date of the most recent payment reconciled with this "
|
||||
"invoice, whatever the reconciliation path (explicit payment "
|
||||
"or direct bank statement line reconciliation).",
|
||||
)
|
||||
|
||||
preferred_payment_method_line_id = fields.Many2one(string="Planned Payment Method")
|
||||
|
||||
@api.depends(
|
||||
"line_ids.matched_debit_ids.debit_move_id.date",
|
||||
"line_ids.matched_debit_ids.debit_move_id.move_id.origin_payment_id.date",
|
||||
"line_ids.matched_debit_ids.debit_move_id.move_id.statement_line_id",
|
||||
"line_ids.matched_credit_ids.credit_move_id.date",
|
||||
"line_ids.matched_credit_ids.credit_move_id.move_id.origin_payment_id.date",
|
||||
"line_ids.matched_credit_ids.credit_move_id.move_id.statement_line_id",
|
||||
)
|
||||
def _compute_last_payment_date(self):
|
||||
"""Compute the date of the last real payment.
|
||||
|
||||
Only customer and vendor invoices carry the information; every
|
||||
other move type gets the field cleared. Candidates are the
|
||||
reconciliation counterpart lines of the receivable/payable
|
||||
lines (exchange difference moves excluded). The most recent
|
||||
date wins.
|
||||
"""
|
||||
for move in self:
|
||||
move.last_payment_date = False
|
||||
if move.move_type not in ("in_invoice", "out_invoice"):
|
||||
continue
|
||||
dates = move._get_last_payment_dates()
|
||||
if dates:
|
||||
move.last_payment_date = max(dates)
|
||||
|
||||
def _get_last_payment_dates(self):
|
||||
"""Collect the dates of the real payments of this invoice.
|
||||
|
||||
A date is collected from each reconciliation counterpart line:
|
||||
|
||||
- counterpart move with ``origin_payment_id``: explicit
|
||||
payment, dated with the payment date;
|
||||
- counterpart move with ``statement_line_id``: direct bank
|
||||
statement reconciliation, dated with the counterpart move
|
||||
date;
|
||||
- any other manual reconciliation is ignored.
|
||||
|
||||
:return: list of dates, possibly empty.
|
||||
"""
|
||||
self.ensure_one()
|
||||
invoice_partials, exchange_diff_moves = self._get_reconciled_invoices_partials()
|
||||
dates = []
|
||||
for _partial, _amount, counterpart_line in invoice_partials:
|
||||
if counterpart_line.move_id.id in exchange_diff_moves:
|
||||
continue
|
||||
payment = counterpart_line.move_id.origin_payment_id
|
||||
if payment:
|
||||
dates.append(payment.date)
|
||||
elif counterpart_line.move_id.statement_line_id:
|
||||
dates.append(counterpart_line.move_id.date)
|
||||
return dates
|
||||
3
account_move_last_payment/pyproject.toml
Normal file
3
account_move_last_payment/pyproject.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
[build-system]
|
||||
requires = ["whool"]
|
||||
build-backend = "whool.buildapi"
|
||||
1
account_move_last_payment/tests/__init__.py
Normal file
1
account_move_last_payment/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_last_payment
|
||||
233
account_move_last_payment/tests/test_last_payment.py
Normal file
233
account_move_last_payment/tests/test_last_payment.py
Normal file
@@ -0,0 +1,233 @@
|
||||
from odoo import fields
|
||||
from odoo.tests import tagged
|
||||
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestAccountMoveLastPayment(AccountTestInvoicingCommon):
|
||||
"""Test the last payment date stored on invoices."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
||||
cls.inbound_method_line = cls.company_data[
|
||||
"default_journal_bank"
|
||||
].inbound_payment_method_line_ids[0]
|
||||
|
||||
@classmethod
|
||||
def _create_posted_invoice(cls, move_type="out_invoice"):
|
||||
"""Create and post a simple invoice without taxes.
|
||||
|
||||
:param str move_type: the invoice type to create.
|
||||
:return: the posted account.move record.
|
||||
"""
|
||||
return cls.init_invoice(move_type, post=True, amounts=[1000.0], taxes=[])
|
||||
|
||||
@classmethod
|
||||
def _register_payment(cls, invoice, date=None, method_line=None, amount=None):
|
||||
"""Register a payment on an invoice through the payment wizard.
|
||||
|
||||
:param invoice: the account.move to pay.
|
||||
:param date: the payment date (defaults to today).
|
||||
:param method_line: the account.payment.method.line to use
|
||||
(defaults to the bank journal inbound method line).
|
||||
:param amount: the payment amount (defaults to the invoice
|
||||
residual).
|
||||
:return: the created account.payment record.
|
||||
"""
|
||||
return (
|
||||
cls.env["account.payment.register"]
|
||||
.with_context(
|
||||
active_model="account.move",
|
||||
active_ids=invoice.ids,
|
||||
)
|
||||
.create(
|
||||
{
|
||||
"payment_date": date or fields.Date.today(),
|
||||
"payment_method_line_id": (
|
||||
method_line or cls.inbound_method_line
|
||||
).id,
|
||||
"amount": amount if amount is not None else invoice.amount_residual,
|
||||
}
|
||||
)
|
||||
._create_payments()
|
||||
)
|
||||
|
||||
def _reconcile_statement_line(self, invoice, amount, date=None):
|
||||
"""Create a bank statement line and reconcile it with the invoice.
|
||||
|
||||
Mirrors the core reconciliation path: the statement line suspense
|
||||
counterpart is re-accounted to the invoice receivable account,
|
||||
then both lines are reconciled together.
|
||||
|
||||
:param invoice: the account.move to settle.
|
||||
:param float amount: the statement line amount.
|
||||
:param date: the statement line date (defaults to today).
|
||||
:return: the created account.bank.statement.line record.
|
||||
"""
|
||||
statement_line = self.env["account.bank.statement.line"].create(
|
||||
{
|
||||
"payment_ref": invoice.name,
|
||||
"journal_id": self.company_data["default_journal_bank"].id,
|
||||
"partner_id": invoice.partner_id.id,
|
||||
"amount": amount,
|
||||
"date": date or fields.Date.today(),
|
||||
}
|
||||
)
|
||||
st_liquidity_lines, st_suspense_lines, _ = statement_line._seek_for_lines()
|
||||
receivable_lines = invoice.line_ids.filtered(
|
||||
lambda line: line.account_type == "asset_receivable"
|
||||
)
|
||||
st_suspense_lines.account_id = receivable_lines.account_id
|
||||
(st_suspense_lines + receivable_lines).reconcile()
|
||||
return statement_line
|
||||
|
||||
def test_register_payment(self):
|
||||
"""Explicit payment: the field matches the payment date."""
|
||||
invoice = self._create_posted_invoice()
|
||||
payment = self._register_payment(invoice)
|
||||
self.assertEqual(invoice.last_payment_date, payment.date)
|
||||
|
||||
def test_bank_statement_reconciliation(self):
|
||||
"""Direct statement reconciliation: the statement date."""
|
||||
invoice = self._create_posted_invoice()
|
||||
yesterday = fields.Date.subtract(fields.Date.today(), days=1)
|
||||
statement_line = self._reconcile_statement_line(
|
||||
invoice, invoice.amount_total, date=yesterday
|
||||
)
|
||||
self.assertEqual(invoice.last_payment_date, statement_line.date)
|
||||
|
||||
def test_list_view_and_export(self):
|
||||
"""The date is stored; date and preferred payment method are listed."""
|
||||
self.assertTrue(self.env["account.move"]._fields["last_payment_date"].store)
|
||||
view = self.env["ir.ui.view"]._get_view_id("account.view_invoice_tree")
|
||||
arch = self.env["account.move"].get_view(view_id=view, view_type="list")["arch"]
|
||||
self.assertIn('name="last_payment_date"', arch)
|
||||
|
||||
def test_multiple_payments_keeps_latest(self):
|
||||
"""With several payments, the most recent candidate wins."""
|
||||
invoice = self._create_posted_invoice()
|
||||
older_date = fields.Date.subtract(fields.Date.today(), days=10)
|
||||
newer_date = fields.Date.subtract(fields.Date.today(), days=2)
|
||||
self._register_payment(invoice, date=older_date, amount=400.0)
|
||||
self._register_payment(invoice, date=newer_date, amount=600.0)
|
||||
self.assertEqual(invoice.last_payment_date, newer_date)
|
||||
|
||||
def test_statement_newer_than_payment(self):
|
||||
"""A more recent statement reconciliation wins over an older payment."""
|
||||
invoice = self._create_posted_invoice()
|
||||
older_date = fields.Date.subtract(fields.Date.today(), days=10)
|
||||
newer_date = fields.Date.subtract(fields.Date.today(), days=2)
|
||||
self._register_payment(invoice, date=older_date, amount=400.0)
|
||||
self._reconcile_statement_line(invoice, 600.0, date=newer_date)
|
||||
self.assertEqual(invoice.last_payment_date, newer_date)
|
||||
|
||||
def test_statement_line_date_change_recompute(self):
|
||||
"""Changing the statement line date updates the stored fields."""
|
||||
invoice = self._create_posted_invoice()
|
||||
yesterday = fields.Date.subtract(fields.Date.today(), days=1)
|
||||
statement_line = self._reconcile_statement_line(
|
||||
invoice, invoice.amount_total, date=yesterday
|
||||
)
|
||||
self.assertEqual(invoice.last_payment_date, yesterday)
|
||||
older_date = fields.Date.subtract(fields.Date.today(), days=30)
|
||||
statement_line.date = older_date
|
||||
self.assertEqual(invoice.last_payment_date, older_date)
|
||||
|
||||
def test_unreconcile_clears_fields(self):
|
||||
"""Unreconciling the invoice clears the field."""
|
||||
invoice = self._create_posted_invoice()
|
||||
self._register_payment(invoice)
|
||||
invoice.line_ids.remove_move_reconcile()
|
||||
self.assertFalse(invoice.last_payment_date)
|
||||
|
||||
def _setup_eur_rates(self, invoice_date, payment_date):
|
||||
"""Set deterministic EUR rates so the payment creates an
|
||||
exchange difference move.
|
||||
|
||||
:param invoice_date: the invoice posting date.
|
||||
:param payment_date: the payment date.
|
||||
:return: the EUR res.currency record.
|
||||
"""
|
||||
eur = self.env.ref("base.EUR")
|
||||
if not eur.active:
|
||||
eur.active = True
|
||||
self.env["res.currency.rate"].search(
|
||||
[
|
||||
("currency_id", "=", eur.id),
|
||||
("name", "in", [invoice_date, payment_date]),
|
||||
]
|
||||
).unlink()
|
||||
self.env["res.currency.rate"].create(
|
||||
[
|
||||
{"currency_id": eur.id, "name": invoice_date, "rate": 1.0},
|
||||
{"currency_id": eur.id, "name": payment_date, "rate": 1.1},
|
||||
]
|
||||
)
|
||||
return eur
|
||||
|
||||
def test_multicurrency_invoice(self):
|
||||
"""A foreign currency payment keeps its real date, and the
|
||||
generated exchange difference move is not taken as a payment."""
|
||||
payment_date = fields.Date.subtract(fields.Date.today(), days=5)
|
||||
invoice_date = fields.Date.from_string("2019-01-01")
|
||||
eur = self._setup_eur_rates(invoice_date, payment_date)
|
||||
invoice = self.init_invoice("out_invoice", post=False, amounts=[1000.0])
|
||||
invoice.currency_id = eur
|
||||
invoice.action_post()
|
||||
payment = self._register_payment(
|
||||
invoice,
|
||||
date=payment_date,
|
||||
amount=invoice.amount_residual,
|
||||
)
|
||||
self.assertTrue(invoice.line_ids.mapped("matched_credit_ids.exchange_move_id"))
|
||||
dates = invoice._get_last_payment_dates()
|
||||
self.assertEqual(dates, [payment.date])
|
||||
self.assertEqual(invoice.last_payment_date, payment.date)
|
||||
|
||||
def test_draft_invoice_is_empty(self):
|
||||
"""A draft invoice has never been reconciled, so the field
|
||||
stays empty."""
|
||||
invoice = self.init_invoice("out_invoice", post=False, amounts=[1000.0])
|
||||
self.assertFalse(invoice.last_payment_date)
|
||||
|
||||
def test_non_invoice_moves_are_empty(self):
|
||||
"""Journal entries and credit notes never carry the field."""
|
||||
invoice = self._create_posted_invoice()
|
||||
self._register_payment(invoice)
|
||||
refund = self._create_posted_invoice(move_type="out_refund")
|
||||
entry = self.env["account.move"].create(
|
||||
{
|
||||
"move_type": "entry",
|
||||
"journal_id": self.company_data["default_journal_misc"].id,
|
||||
"date": fields.Date.today(),
|
||||
"line_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"account_id": self.company_data[
|
||||
"default_account_revenue"
|
||||
].id,
|
||||
"debit": 100.0,
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"account_id": self.company_data[
|
||||
"default_account_receivable"
|
||||
].id,
|
||||
"credit": 100.0,
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
entry.action_post()
|
||||
self.assertFalse(refund.last_payment_date)
|
||||
self.assertFalse(entry.last_payment_date)
|
||||
self.assertTrue(invoice.last_payment_date)
|
||||
13
account_move_last_payment/views/account_move_views.xml
Normal file
13
account_move_last_payment/views/account_move_views.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_invoice_tree_last_payment" model="ir.ui.view">
|
||||
<field name="name">account.invoice.list.last.payment</field>
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_invoice_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="amount_residual_signed" position="after">
|
||||
<field name="last_payment_date" optional="show" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user