From 74e7690c049c4dbef88fb5aeaec8a7292b84bf30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 6 Jan 2026 11:38:37 +0100 Subject: [PATCH] Add cron job to reconcile move lines Closes #14468 --- modules/account/CHANGELOG | 1 + modules/account/doc/usage/process.inc.rst | 3 +++ modules/account/ir.py | 16 ++++++++++++++++ modules/account/move.py | 15 +++++++++++++++ .../scenario_account_reconcile_automatic.rst | 10 ++++++---- modules/account/tryton.cfg | 1 + 6 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 modules/account/ir.py diff --git a/modules/account/CHANGELOG b/modules/account/CHANGELOG index a00bced77a..0326448da5 100644 --- a/modules/account/CHANGELOG +++ b/modules/account/CHANGELOG @@ -1,3 +1,4 @@ +* Add cron job to reconcile move lines Version 7.8.0 - 2025-12-15 -------------------------- diff --git a/modules/account/doc/usage/process.inc.rst b/modules/account/doc/usage/process.inc.rst index 3ac815f3ff..f93d7fca98 100644 --- a/modules/account/doc/usage/process.inc.rst +++ b/modules/account/doc/usage/process.inc.rst @@ -15,6 +15,9 @@ account move line's :guilabel:`Reconciliation` field. The `Reconcile Accounts ` wizard is used to manually run this account reconciliation. +You may want to define some :guilabel:`Reconcile Move Lines Automatically` +`scheduled tasks ` to automate the reconciliation. + .. note:: Some other processes in Tryton will automatically reconcile account move diff --git a/modules/account/ir.py b/modules/account/ir.py new file mode 100644 index 0000000000..8b7985b227 --- /dev/null +++ b/modules/account/ir.py @@ -0,0 +1,16 @@ +# The COPYRIGHT file at the top level of this repository contains the full +# copyright notices and license terms. + +from trytond.pool import PoolMeta + + +class Cron(metaclass=PoolMeta): + __name__ = 'ir.cron' + + @classmethod + def __setup__(cls): + super().__setup__() + cls.method.selection.extend([ + ('account.move.line|reconcile_automatic', + "Reconcile Move Lines Automatically"), + ]) diff --git a/modules/account/move.py b/modules/account/move.py index 4d87645bdc..281d1fc7ea 100644 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -1864,6 +1864,21 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): def _reconciliation_sort_key(self): return self.maturity_date or self.date + @classmethod + def reconcile_automatic(cls, data=None): + pool = Pool() + Reconcile = pool.get('account.reconcile', type='wizard') + + data = data.copy() if data is not None else {} + data['start'] = { + 'automatic': True, + 'only_balanced': True, + } + + session_id, _, _ = Reconcile.create() + Reconcile.execute(session_id, data, 'setup') + Reconcile.delete(session_id) + class LineReceivablePayableContext(ModelView): __name__ = 'account.move.line.receivable_payable.context' diff --git a/modules/account/tests/scenario_account_reconcile_automatic.rst b/modules/account/tests/scenario_account_reconcile_automatic.rst index ef956ce843..f64b3e2243 100644 --- a/modules/account/tests/scenario_account_reconcile_automatic.rst +++ b/modules/account/tests/scenario_account_reconcile_automatic.rst @@ -6,7 +6,7 @@ Imports:: >>> from decimal import Decimal - >>> from proteus import Model, Wizard + >>> from proteus import Model >>> from trytond.modules.account.tests.tools import ( ... create_chart, create_fiscalyear, get_accounts) >>> from trytond.modules.company.tests.tools import create_company @@ -16,6 +16,7 @@ Activate modules:: >>> config = activate_modules('account', create_company, create_chart) + >>> Cron = Model.get('ir.cron') >>> Journal = Model.get('account.journal') >>> Line = Model.get('account.move.line') >>> Move = Model.get('account.move') @@ -73,9 +74,10 @@ Create Moves to reconcile:: Run Reconcile wizard:: - >>> reconcile = Wizard('account.reconcile') - >>> reconcile.form.automatic = True - >>> reconcile.execute('setup') + >>> reconcile = Cron( + ... method='account.move.line|reconcile_automatic', + ... interval_number=1, interval_type='days') + >>> reconcile.click('run_once') >>> lines = Line.find([('account', '=', accounts['receivable'].id)]) >>> len(lines) diff --git a/modules/account/tryton.cfg b/modules/account/tryton.cfg index 485e4b31d0..78cc5e3d6f 100644 --- a/modules/account/tryton.cfg +++ b/modules/account/tryton.cfg @@ -25,6 +25,7 @@ xml: [register] model: + ir.Cron fiscalyear.FiscalYear fiscalyear.BalanceNonDeferralStart company.Company