Each reconciliation as a job

Add an option to create one job per reconciliation.
The aim is to make it more resilient to failure with large amount of
data.
This commit is contained in:
Yannick Vaucher
2022-01-12 09:58:13 +01:00
committed by Akim Juillerat
parent fc4c93c19d
commit 5b45b6029b
2 changed files with 48 additions and 0 deletions

View File

@@ -1 +1,2 @@
from . import mass_reconcile
from . import base_reconciliation

View File

@@ -0,0 +1,47 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import ast
import logging
from odoo import models
_logger = logging.getLogger(__name__)
try:
from odoo.addons.queue_job.job import job
except ImportError:
_logger.debug('Can not `import queue_job`.')
class MassReconcileBase(models.AbstractModel):
_inherit = 'mass.reconcile.base'
# WARNING: this has limitation as it creates a job based on an object wizard
# when the transient model will be garbadge collected the job won't
# be able to run anymore.
# FIXME: move or copy wizard data configuration in a standard model or refactor
# to have it as a parameter.
def _reconcile_lines(self, lines, allow_partial=False):
as_job = self.env['ir.config_parameter'].sudo().get_param(
'account.mass.reconcile.lines.as.job', default=False
)
try:
as_job = ast.literal_eval(as_job) if as_job else False
except ValueError:
as_job = False
if as_job and self.env.context.get("reconcile_lines_as_job", True):
self.with_delay().reconcile_lines_as_job(
lines,
allow_partial=allow_partial
)
# Report is not available with reconcile jobs
return False, False
else:
return super()._reconcile_lines(lines, allow_partial=allow_partial)
@job(default_channel='root.mass_reconcile')
def reconcile_lines_as_job(self, lines, allow_partial=False):
self.with_context(reconcile_lines_as_job=False)._reconcile_lines(lines, allow_partial=allow_partial)