[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.
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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'])
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
<group>
|
||||
<field name="auto_reconcile" attrs="{'invisible': [('rule_type', '=', 'writeoff_button')]}"/>
|
||||
<field name="to_check" attrs="{'invisible': [('rule_type', '!=', 'writeoff_button')]}"/>
|
||||
<field name="past_months_limit" attrs="{'invisible': [('rule_type', '!=', 'invoice_matching')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="Conditions on Bank Statement Line">
|
||||
|
||||
Reference in New Issue
Block a user