2017-03-23 07:52:07 +01:00
|
|
|
# Copyright 2016-2017 ACSONE SA/NV
|
2016-08-25 15:26:49 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
|
|
|
import logging
|
2021-02-22 17:48:48 +01:00
|
|
|
|
|
|
|
from odoo import _, api, fields, models
|
|
|
|
|
2016-08-25 15:26:49 +02:00
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
try:
|
2017-03-23 07:52:07 +01:00
|
|
|
from odoo.addons.queue_job.job import job
|
2016-08-25 15:26:49 +02:00
|
|
|
except ImportError:
|
2021-02-22 17:48:48 +01:00
|
|
|
_logger.debug("Can not `import queue_job`.")
|
2016-08-25 15:26:49 +02:00
|
|
|
|
|
|
|
|
2019-10-31 07:20:20 +01:00
|
|
|
class AccountAssetCompute(models.TransientModel):
|
2016-08-25 15:26:49 +02:00
|
|
|
|
2021-02-22 17:48:48 +01:00
|
|
|
_inherit = "account.asset.compute"
|
2016-08-25 15:26:49 +02:00
|
|
|
|
|
|
|
batch_processing = fields.Boolean()
|
|
|
|
|
|
|
|
@api.multi
|
2021-02-22 17:48:48 +01:00
|
|
|
@job(default_channel="root.account_asset_batch_compute")
|
2016-08-25 15:26:49 +02:00
|
|
|
def asset_compute(self):
|
|
|
|
self.ensure_one()
|
|
|
|
if not self.batch_processing:
|
2019-10-31 07:20:20 +01:00
|
|
|
return super(AccountAssetCompute, self).asset_compute()
|
2021-02-22 17:48:48 +01:00
|
|
|
if not self.env.context.get("job_uuid") and not self.env.context.get(
|
|
|
|
"test_queue_job_no_delay"
|
2019-11-03 22:08:09 +01:00
|
|
|
):
|
2021-02-22 17:48:48 +01:00
|
|
|
description = _("Creating jobs to create moves for assets to %s") % (
|
|
|
|
self.date_end,
|
|
|
|
)
|
2017-03-23 07:52:07 +01:00
|
|
|
job = self.with_delay(description=description).asset_compute()
|
2021-02-22 17:48:48 +01:00
|
|
|
return u"Job created with uuid {}".format(job.uuid)
|
2016-08-25 15:26:49 +02:00
|
|
|
else:
|
2019-10-31 07:20:20 +01:00
|
|
|
return super(
|
2021-02-22 17:48:48 +01:00
|
|
|
AccountAssetCompute, self.with_context(asset_batch_processing=True)
|
|
|
|
).asset_compute()
|