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 @@
+