From d6b87de53caeab2977b84728ac022e8605ecb7ac Mon Sep 17 00:00:00 2001 From: maud-buchwalter Date: Thu, 29 Oct 2026 12:07:30 +0100 Subject: [PATCH] [IMP] account_move_last_payment retrieve only the date --- .../i18n/account_move_last_payment.pot | 47 ++++++++++++++ account_move_last_payment/i18n/fr.po | 43 +++++------- .../models/account_move.py | 65 ++++++++----------- .../tests/test_last_payment.py | 50 +++++++------- .../views/account_move_views.xml | 7 +- 5 files changed, 115 insertions(+), 97 deletions(-) create mode 100644 account_move_last_payment/i18n/account_move_last_payment.pot diff --git a/account_move_last_payment/i18n/account_move_last_payment.pot b/account_move_last_payment/i18n/account_move_last_payment.pot new file mode 100644 index 0000000..87e96da --- /dev/null +++ b/account_move_last_payment/i18n/account_move_last_payment.pot @@ -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 "" diff --git a/account_move_last_payment/i18n/fr.po b/account_move_last_payment/i18n/fr.po index f24c5cc..1b13d3a 100644 --- a/account_move_last_payment/i18n/fr.po +++ b/account_move_last_payment/i18n/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 18.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-10-20 15:23+0000\n" -"PO-Revision-Date: 2026-10-20 15:23+0000\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" @@ -16,39 +16,30 @@ msgstr "" "Plural-Forms: \n" #. module: account_move_last_payment -#: code:addons/account_move_last_payment/models/account_move.py:0 -msgid "Bank Transfer" -msgstr "Virement" - -#. module: account_move_last_payment -#: 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_move__last_payment_method -msgid "Last Payment Method" -msgstr "Mode de paiement" - -#. 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 " +"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.fields,help:account_move_last_payment.field_account_move__last_payment_method -msgid "" -"Payment method of the most recent payment reconciled with this invoice." -msgstr "" -"Mode de paiement du paiement le plus récent lettré avec cette facture." - #. 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" diff --git a/account_move_last_payment/models/account_move.py b/account_move_last_payment/models/account_move.py index 973ab44..0369e90 100644 --- a/account_move_last_payment/models/account_move.py +++ b/account_move_last_payment/models/account_move.py @@ -1,3 +1,6 @@ +# Copyright 2026 Elabore +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from odoo import api, fields, models @@ -5,80 +8,64 @@ class AccountMove(models.Model): _inherit = "account.move" last_payment_date = fields.Date( - compute="_compute_last_payment_info", + 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).", ) - last_payment_method = fields.Char( - compute="_compute_last_payment_info", - store=True, - copy=False, - help="Payment method of the most recent payment reconciled with this invoice.", - ) + + 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.payment_method_line_id.name", + "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.payment_method_line_id.name", + "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_info(self): - """Compute the last real payment date and method. + 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 both fields cleared. Candidates are the + 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 - candidate wins; on equal dates the first candidate found wins. + date wins. """ for move in self: + move.last_payment_date = False if move.move_type not in ("in_invoice", "out_invoice"): - move.last_payment_date = False - move.last_payment_method = False continue - candidates = move._get_last_payment_candidates() - if not candidates: - move.last_payment_date = False - move.last_payment_method = False - else: - latest_date, latest_method = max( - candidates, key=lambda candidate: candidate[0] - ) - move.last_payment_date = latest_date - move.last_payment_method = latest_method + dates = move._get_last_payment_dates() + if dates: + move.last_payment_date = max(dates) - def _get_last_payment_candidates(self): - """Collect the candidate real payments for this invoice. + def _get_last_payment_dates(self): + """Collect the dates of the real payments of this invoice. - A candidate is a ``(date, method)`` tuple built from each - reconciliation counterpart line: + A date is collected from each reconciliation counterpart line: - counterpart move with ``origin_payment_id``: explicit - payment, dated with the payment date, method from the - payment method line; + payment, dated with the payment date; - counterpart move with ``statement_line_id``: direct bank statement reconciliation, dated with the counterpart move - date, method fixed to the bank transfer label; + date; - any other manual reconciliation is ignored. - :return: list of ``(date, method)`` tuples, possibly empty. + :return: list of dates, possibly empty. """ self.ensure_one() invoice_partials, exchange_diff_moves = self._get_reconciled_invoices_partials() - candidates = [] + 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: - candidates.append((payment.date, payment.payment_method_line_id.name)) + dates.append(payment.date) elif counterpart_line.move_id.statement_line_id: - candidates.append( - (counterpart_line.move_id.date, self.env._("Bank Transfer")) - ) - return candidates + dates.append(counterpart_line.move_id.date) + return dates \ No newline at end of file diff --git a/account_move_last_payment/tests/test_last_payment.py b/account_move_last_payment/tests/test_last_payment.py index 0246940..b94282e 100644 --- a/account_move_last_payment/tests/test_last_payment.py +++ b/account_move_last_payment/tests/test_last_payment.py @@ -6,7 +6,7 @@ from odoo.addons.account.tests.common import AccountTestInvoicingCommon @tagged("post_install", "-at_install") class TestAccountMoveLastPayment(AccountTestInvoicingCommon): - """Test the last payment date and method stored on invoices.""" + """Test the last payment date stored on invoices.""" @classmethod def setUpClass(cls): @@ -85,32 +85,26 @@ class TestAccountMoveLastPayment(AccountTestInvoicingCommon): return statement_line def test_register_payment(self): - """Explicit payment: fields match the payment date and method.""" + """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) - self.assertEqual( - invoice.last_payment_method, payment.payment_method_line_id.name - ) def test_bank_statement_reconciliation(self): - """Direct statement reconciliation: statement date + Bank Transfer.""" + """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) - self.assertEqual(invoice.last_payment_method, "Bank Transfer") def test_list_view_and_export(self): - """Both fields are stored and shown in the invoice list view.""" + """The date is stored; date and preferred payment method are listed.""" self.assertTrue(self.env["account.move"]._fields["last_payment_date"].store) - self.assertTrue(self.env["account.move"]._fields["last_payment_method"].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) - self.assertIn('name="last_payment_method"', arch) def test_multiple_payments_keeps_latest(self): """With several payments, the most recent candidate wins.""" @@ -120,7 +114,15 @@ class TestAccountMoveLastPayment(AccountTestInvoicingCommon): 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) - self.assertEqual(invoice.last_payment_method, self.inbound_method_line.name) + + 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.""" @@ -135,12 +137,11 @@ class TestAccountMoveLastPayment(AccountTestInvoicingCommon): self.assertEqual(invoice.last_payment_date, older_date) def test_unreconcile_clears_fields(self): - """Unreconciling the invoice clears both fields.""" + """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) - self.assertFalse(invoice.last_payment_method) def _setup_eur_rates(self, invoice_date, payment_date): """Set deterministic EUR rates so the payment creates an @@ -168,9 +169,8 @@ class TestAccountMoveLastPayment(AccountTestInvoicingCommon): return eur def test_multicurrency_invoice(self): - """A foreign currency payment keeps its real date and method, - and the generated exchange difference move is not taken as a - payment candidate.""" + """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) @@ -183,22 +183,18 @@ class TestAccountMoveLastPayment(AccountTestInvoicingCommon): amount=invoice.amount_residual, ) self.assertTrue(invoice.line_ids.mapped("matched_credit_ids.exchange_move_id")) - candidates = invoice._get_last_payment_candidates() - self.assertEqual(len(candidates), 1) + dates = invoice._get_last_payment_dates() + self.assertEqual(dates, [payment.date]) self.assertEqual(invoice.last_payment_date, payment.date) - self.assertEqual( - invoice.last_payment_method, payment.payment_method_line_id.name - ) def test_draft_invoice_is_empty(self): - """A draft invoice has never been reconciled, so both fields - stay empty.""" + """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) - self.assertFalse(invoice.last_payment_method) def test_non_invoice_moves_are_empty(self): - """Journal entries and credit notes never carry the fields.""" + """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") @@ -233,7 +229,5 @@ class TestAccountMoveLastPayment(AccountTestInvoicingCommon): ) entry.action_post() self.assertFalse(refund.last_payment_date) - self.assertFalse(refund.last_payment_method) self.assertFalse(entry.last_payment_date) - self.assertFalse(entry.last_payment_method) - self.assertTrue(invoice.last_payment_date) + self.assertTrue(invoice.last_payment_date) \ No newline at end of file diff --git a/account_move_last_payment/views/account_move_views.xml b/account_move_last_payment/views/account_move_views.xml index 92ed765..ecb9f46 100644 --- a/account_move_last_payment/views/account_move_views.xml +++ b/account_move_last_payment/views/account_move_views.xml @@ -3,12 +3,11 @@ account.invoice.list.last.payment account.move - + - - + - + \ No newline at end of file