From 02f7023b54d35a5b13481ca77cd2ddd15c022ffe Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Fri, 12 Jun 2020 14:52:05 +0000 Subject: [PATCH] [IMP] account: introduce a date limit on the application of reconciliation models This limit is set by the past_months_limit field of reconciliation models. When set, it specifies the number of months in the past to search for matches when using this model. Older move lines will be ignored. The point of this feature is to exclude too old stuff that we know we won't reconcile (because of import, old misconfiguration, former misuse of some features, ...). It also allows reducing the number of move lines taken into consideration, and solving perfomance issues functionnally by isolating the move lines into smaller periods to reconcile them separately. --- addons/account/models/account_reconcile_model.py | 9 +++++++++ addons/account/tests/test_templates_consistency.py | 2 +- addons/account/views/account_reconcile_model_views.xml | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index 6cf1499c7a7..42138f74e7b 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -174,6 +174,8 @@ class AccountReconcileModel(models.Model): line_ids = fields.One2many('account.reconcile.model.line', 'model_id') + past_months_limit = fields.Integer(string="Past Months Limit", default=18, help="Number of months in the past to consider entries from when applying this model.") + decimal_separator = fields.Char(default=lambda self: self.env['res.lang']._lang_get(self.env.user.lang).decimal_point, help="Every character that is nor a digit nor this separator will be removed from the matching string") show_decimal_separator = fields.Boolean(compute='_compute_show_decimal_separator', help="Technical field to decide if we should show the decimal separator for the regex matching field.") number_entries = fields.Integer(string='Number of entries related to this model', compute='_compute_number_entries') @@ -608,6 +610,13 @@ class AccountReconcileModel(models.Model): 'model_id': self.id, } + # If this reconciliation model defines a past_months_limit, we add a condition + # to the query to only search on move lines that are younger than this limit. + if self.past_months_limit: + date_limit = fields.Date.today() - relativedelta(months=self.past_months_limit) + query += "AND aml.date >= %(aml_date_limit)s" + params['aml_date_limit'] = date_limit + # Filter out excluded account.move.line. if excluded_ids: query += 'AND aml.id NOT IN %(excluded_aml_ids)s' diff --git a/addons/account/tests/test_templates_consistency.py b/addons/account/tests/test_templates_consistency.py index 40a89d8a124..2e41123db5a 100644 --- a/addons/account/tests/test_templates_consistency.py +++ b/addons/account/tests/test_templates_consistency.py @@ -61,7 +61,7 @@ class AccountingTestTemplConsistency(TransactionCase): '''Test fields consistency for ('account.reconcile.model', 'account.reconcile.model.template') ''' self.check_fields_consistency('account.reconcile.model.template', 'account.reconcile.model', exceptions=['chart_template_id']) - self.check_fields_consistency('account.reconcile.model', 'account.reconcile.model.template', exceptions=['company_id']) + self.check_fields_consistency('account.reconcile.model', 'account.reconcile.model.template', exceptions=['company_id', 'past_months_limit']) # lines self.check_fields_consistency('account.reconcile.model.line.template', 'account.reconcile.model.line', exceptions=['chart_template_id']) self.check_fields_consistency('account.reconcile.model.line', 'account.reconcile.model.line.template', exceptions=['company_id', 'journal_id', 'analytic_account_id', 'analytic_tag_ids', 'amount']) diff --git a/addons/account/views/account_reconcile_model_views.xml b/addons/account/views/account_reconcile_model_views.xml index 5b93d48f9ce..3f5c4ff4ac2 100644 --- a/addons/account/views/account_reconcile_model_views.xml +++ b/addons/account/views/account_reconcile_model_views.xml @@ -78,6 +78,7 @@ +