From 7f0ffc22e67feb92eb492b7c46b3e394f032a955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 3 Jan 2026 19:18:24 +0100 Subject: [PATCH] Update numbered at when refreshing invoice report Closes #14462 --- .../account_invoice.py | 14 ++++ modules/account_invoice_history/setup.py | 7 +- .../scenario_invoice_report_revision.rst | 72 +++++++++++++++++++ .../tests/test_scenario.py | 8 +++ modules/account_invoice_history/tryton.cfg | 2 + 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 modules/account_invoice_history/tests/scenario_invoice_report_revision.rst create mode 100644 modules/account_invoice_history/tests/test_scenario.py diff --git a/modules/account_invoice_history/account_invoice.py b/modules/account_invoice_history/account_invoice.py index b028ba2956..55e6d34f69 100644 --- a/modules/account_invoice_history/account_invoice.py +++ b/modules/account_invoice_history/account_invoice.py @@ -1,5 +1,8 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. + +from sql.functions import CurrentTimestamp + from trytond.pool import PoolMeta @@ -16,3 +19,14 @@ class PaymentTermLine(metaclass=PoolMeta): class PaymentTermLineRelativeDelta(metaclass=PoolMeta): __name__ = 'account.invoice.payment_term.line.delta' _history = True + + +class RefreshInvoiceReport(metaclass=PoolMeta): + __name__ = 'account.invoice.refresh_invoice_report' + + def transition_archive(self): + if records := [r for r in self.records if r.numbered_at]: + self.model.write(records, { + 'numbered_at': CurrentTimestamp(), + }) + return super().transition_archive() diff --git a/modules/account_invoice_history/setup.py b/modules/account_invoice_history/setup.py index 3ab9ee1af2..1e0824cc58 100755 --- a/modules/account_invoice_history/setup.py +++ b/modules/account_invoice_history/setup.py @@ -50,6 +50,8 @@ for dep in info.get('depends', []): requires.append(get_require_version('trytond_%s' % dep)) requires.append(get_require_version('trytond')) +tests_require = [get_require_version('proteus')] + setup(name=name, version=version, description='Tryton module to historize invoices', @@ -74,7 +76,7 @@ setup(name=name, ), package_data={ 'trytond.modules.account_invoice_history': (info.get('xml', []) - + ['tryton.cfg', 'locale/*.po']), + + ['tryton.cfg', 'locale/*.po', 'tests/*.rst']), }, classifiers=[ 'Development Status :: 5 - Production/Stable', @@ -120,6 +122,9 @@ setup(name=name, license='GPL-3', python_requires='>=3.9', install_requires=requires, + extras_require={ + 'test': tests_require, + }, zip_safe=False, entry_points=""" [trytond.modules] diff --git a/modules/account_invoice_history/tests/scenario_invoice_report_revision.rst b/modules/account_invoice_history/tests/scenario_invoice_report_revision.rst new file mode 100644 index 0000000000..a3f43060bb --- /dev/null +++ b/modules/account_invoice_history/tests/scenario_invoice_report_revision.rst @@ -0,0 +1,72 @@ +================================ +Invoice Report Revision Scenario +================================ + +Imports:: + + >>> import datetime as dt + >>> from decimal import Decimal + + >>> from proteus import Model, Wizard + >>> from trytond.modules.account.tests.tools import ( + ... create_chart, create_fiscalyear, get_accounts) + >>> from trytond.modules.account_invoice.tests.tools import ( + ... set_fiscalyear_invoice_sequences) + >>> from trytond.modules.company.tests.tools import create_company + >>> from trytond.tests.tools import activate_modules, assertNotEqual + + >>> today = dt.date.today() + +Activate modules:: + + >>> config = activate_modules( + ... 'account_invoice_history', create_company, create_chart) + + >>> Invoice = Model.get('account.invoice') + >>> Journal = Model.get('account.journal') + >>> Move = Model.get('account.move') + >>> Party = Model.get('party.party') + >>> PaymentMethod = Model.get('account.invoice.payment.method') + >>> ProductCategory = Model.get('product.category') + >>> ProductTemplate = Model.get('product.template') + >>> ProductUom = Model.get('product.uom') + >>> Sequence = Model.get('ir.sequence') + +Create fiscal year:: + + >>> fiscalyear = set_fiscalyear_invoice_sequences( + ... create_fiscalyear()) + >>> fiscalyear.click('create_period') + >>> period = fiscalyear.periods[0] + +Get accounts:: + + >>> accounts = get_accounts() + +Create party:: + + >>> party = Party(name="Party") + >>> party.save() + +Post an invoice:: + + >>> invoice = Invoice() + >>> invoice.type = 'out' + >>> invoice.party = party + >>> invoice.invoice_date = today + >>> line = invoice.lines.new() + >>> line.account = accounts['revenue'] + >>> line.quantity = 5 + >>> line.unit_price = Decimal('20') + >>> invoice.click('post') + >>> invoice.state + 'posted' + + >>> numbered_at = invoice.numbered_at + +Execute update invoice report wizard:: + + >>> refresh_invoice_report = Wizard( + ... 'account.invoice.refresh_invoice_report', [invoice]) + + >>> assertNotEqual(invoice.numbered_at, numbered_at) diff --git a/modules/account_invoice_history/tests/test_scenario.py b/modules/account_invoice_history/tests/test_scenario.py new file mode 100644 index 0000000000..dc1d23e7e5 --- /dev/null +++ b/modules/account_invoice_history/tests/test_scenario.py @@ -0,0 +1,8 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. + +from trytond.tests.test_tryton import load_doc_tests + + +def load_tests(*args, **kwargs): + return load_doc_tests(__name__, __file__, *args, **kwargs) diff --git a/modules/account_invoice_history/tryton.cfg b/modules/account_invoice_history/tryton.cfg index 329eb2922a..5d415c59c5 100644 --- a/modules/account_invoice_history/tryton.cfg +++ b/modules/account_invoice_history/tryton.cfg @@ -13,3 +13,5 @@ model: account_invoice.PaymentTerm account_invoice.PaymentTermLine account_invoice.PaymentTermLineRelativeDelta +wizard: + account_invoice.RefreshInvoiceReport