From 21890ebe64217c26cf8220440d98c0393a335a6b Mon Sep 17 00:00:00 2001 From: Saran440 Date: Tue, 23 Aug 2022 09:53:12 +0700 Subject: [PATCH] [14.0][ADD] account_asset_compute_batch_job --- account_asset_compute_batch_job/README.rst | 83 ++++ account_asset_compute_batch_job/__init__.py | 3 + .../__manifest__.py | 17 + .../data/queue_data.xml | 18 + .../models/__init__.py | 3 + .../models/account_asset_compute_batch.py | 46 ++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 2 + .../readme/USAGE.rst | 5 + .../security/ir.model.access.csv | 2 + .../static/description/index.html | 430 ++++++++++++++++++ .../tests/__init__.py | 3 + .../test_account_asset_compute_batch_job.py | 35 ++ .../views/account_asset_compute_batch.xml | 90 ++++ oca_dependencies.txt | 1 + .../addons/account_asset_compute_batch_job | 1 + .../account_asset_compute_batch_job/setup.py | 6 + 17 files changed, 746 insertions(+) create mode 100644 account_asset_compute_batch_job/README.rst create mode 100644 account_asset_compute_batch_job/__init__.py create mode 100644 account_asset_compute_batch_job/__manifest__.py create mode 100644 account_asset_compute_batch_job/data/queue_data.xml create mode 100644 account_asset_compute_batch_job/models/__init__.py create mode 100644 account_asset_compute_batch_job/models/account_asset_compute_batch.py create mode 100644 account_asset_compute_batch_job/readme/CONTRIBUTORS.rst create mode 100644 account_asset_compute_batch_job/readme/DESCRIPTION.rst create mode 100644 account_asset_compute_batch_job/readme/USAGE.rst create mode 100644 account_asset_compute_batch_job/security/ir.model.access.csv create mode 100644 account_asset_compute_batch_job/static/description/index.html create mode 100644 account_asset_compute_batch_job/tests/__init__.py create mode 100644 account_asset_compute_batch_job/tests/test_account_asset_compute_batch_job.py create mode 100644 account_asset_compute_batch_job/views/account_asset_compute_batch.xml create mode 120000 setup/account_asset_compute_batch_job/odoo/addons/account_asset_compute_batch_job create mode 100644 setup/account_asset_compute_batch_job/setup.py diff --git a/account_asset_compute_batch_job/README.rst b/account_asset_compute_batch_job/README.rst new file mode 100644 index 000000000000..6aa79e0581ad --- /dev/null +++ b/account_asset_compute_batch_job/README.rst @@ -0,0 +1,83 @@ +=============================================== +Assets - Compute Depre. with Job Queue in Batch +=============================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github + :target: https://github.com/OCA/account-financial-tools/tree/14.0/account_asset_compute_batch_job + :alt: OCA/account-financial-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-financial-tools-14-0/account-financial-tools-14-0-account_asset_compute_batch_job + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/92/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add the possibility to compute assets batch with job queue. +This module adds a new button for compute in order to execute this process in job queue. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Configured job queue +#. Create Compute Asset Batch directly +#. Click "Compute as Background" button to compute asset with job. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Ecosoft + +Contributors +~~~~~~~~~~~~ + +* Saran Lim. + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/account-financial-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_asset_compute_batch_job/__init__.py b/account_asset_compute_batch_job/__init__.py new file mode 100644 index 000000000000..69f7babdfb1a --- /dev/null +++ b/account_asset_compute_batch_job/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/account_asset_compute_batch_job/__manifest__.py b/account_asset_compute_batch_job/__manifest__.py new file mode 100644 index 000000000000..05585d6b0961 --- /dev/null +++ b/account_asset_compute_batch_job/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2022 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Assets - Compute Depre. with Job Queue in Batch", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "depends": ["account_asset_compute_batch", "queue_job"], + "author": "Ecosoft, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-financial-tools", + "category": "Accounting & Finance", + "data": [ + "security/ir.model.access.csv", + "data/queue_data.xml", + "views/account_asset_compute_batch.xml", + ], +} diff --git a/account_asset_compute_batch_job/data/queue_data.xml b/account_asset_compute_batch_job/data/queue_data.xml new file mode 100644 index 000000000000..a51a3818ebc0 --- /dev/null +++ b/account_asset_compute_batch_job/data/queue_data.xml @@ -0,0 +1,18 @@ + + + + account_asset_compute_batch + + + + + action_compute + + + diff --git a/account_asset_compute_batch_job/models/__init__.py b/account_asset_compute_batch_job/models/__init__.py new file mode 100644 index 000000000000..1d2eb410b861 --- /dev/null +++ b/account_asset_compute_batch_job/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import account_asset_compute_batch diff --git a/account_asset_compute_batch_job/models/account_asset_compute_batch.py b/account_asset_compute_batch_job/models/account_asset_compute_batch.py new file mode 100644 index 000000000000..fe8a8d35fb7e --- /dev/null +++ b/account_asset_compute_batch_job/models/account_asset_compute_batch.py @@ -0,0 +1,46 @@ +# Copyright 2022 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, fields, models + + +class AssetComputeBatch(models.Model): + _inherit = "account.asset.compute.batch" + + job_ids = fields.Many2many( + comodel_name="queue.job", + column1="batch_id", + column2="job_id", + relation="asset_batch_job_rel", + copy=False, + ) + job_current = fields.Many2one(comodel_name="queue.job", readonly=True) + job_state = fields.Selection(string="Job State", related="job_current.state") + + def action_compute_job(self): + self.ensure_one() + queue_obj = self.env["queue.job"] + if not self.env.context.get("job_uuid") and not self.env.context.get( + "test_queue_job_no_delay" + ): + description = _("Creating jobs to create moves for assets to %s") % ( + self.date_end, + ) + new_delay = self.with_delay(description=description).action_compute() + job = queue_obj.search([("uuid", "=", new_delay.uuid)]) + self.job_ids = [(4, job.id)] + self.job_current = job.id + return "Job created with uuid {}".format(new_delay.uuid) + return super().action_compute() + + def open_queue_job(self): + self.ensure_one() + action = { + "name": _("Jobs"), + "view_type": "tree", + "view_mode": "list,form", + "res_model": "queue.job", + "type": "ir.actions.act_window", + "domain": [("id", "in", self.job_ids.ids)], + } + return action diff --git a/account_asset_compute_batch_job/readme/CONTRIBUTORS.rst b/account_asset_compute_batch_job/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..cc6b23102b9d --- /dev/null +++ b/account_asset_compute_batch_job/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Saran Lim. diff --git a/account_asset_compute_batch_job/readme/DESCRIPTION.rst b/account_asset_compute_batch_job/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..fe679283e301 --- /dev/null +++ b/account_asset_compute_batch_job/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Add the possibility to compute assets batch with job queue. +This module adds a new button for compute in order to execute this process in job queue. diff --git a/account_asset_compute_batch_job/readme/USAGE.rst b/account_asset_compute_batch_job/readme/USAGE.rst new file mode 100644 index 000000000000..13867cd04af3 --- /dev/null +++ b/account_asset_compute_batch_job/readme/USAGE.rst @@ -0,0 +1,5 @@ +To use this module, you need to: + +#. Configured job queue +#. Create Compute Asset Batch directly +#. Click "Compute as Background" button to compute asset with job. diff --git a/account_asset_compute_batch_job/security/ir.model.access.csv b/account_asset_compute_batch_job/security/ir.model.access.csv new file mode 100644 index 000000000000..f363c9e29312 --- /dev/null +++ b/account_asset_compute_batch_job/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_job_queue_account_readonly,access_job_queue_account_readonly,queue_job.model_queue_job,account.group_account_invoice,1,0,0,0 diff --git a/account_asset_compute_batch_job/static/description/index.html b/account_asset_compute_batch_job/static/description/index.html new file mode 100644 index 000000000000..d369fb65d2de --- /dev/null +++ b/account_asset_compute_batch_job/static/description/index.html @@ -0,0 +1,430 @@ + + + + + + +Assets - Compute Depre. with Job Queue in Batch + + + +
+

Assets - Compute Depre. with Job Queue in Batch

+ + +

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runbot

+

Add the possibility to compute assets batch with job queue. +This module adds a new button for compute in order to execute this process in job queue.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Configured job queue
  2. +
  3. Create Compute Asset Batch directly
  4. +
  5. Click “Compute as Background” button to compute asset with job.
  6. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Ecosoft
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/account-financial-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_asset_compute_batch_job/tests/__init__.py b/account_asset_compute_batch_job/tests/__init__.py new file mode 100644 index 000000000000..8b7febdc591a --- /dev/null +++ b/account_asset_compute_batch_job/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_account_asset_compute_batch_job diff --git a/account_asset_compute_batch_job/tests/test_account_asset_compute_batch_job.py b/account_asset_compute_batch_job/tests/test_account_asset_compute_batch_job.py new file mode 100644 index 000000000000..d2ef80e68295 --- /dev/null +++ b/account_asset_compute_batch_job/tests/test_account_asset_compute_batch_job.py @@ -0,0 +1,35 @@ +# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import tagged + +from odoo.addons.account_asset_compute_batch.tests.test_account_asset_compute_batch import ( + TestAssetComputeBatch, +) + + +@tagged("post_install", "-at_install") +class TestAssetComputeBatchJob(TestAssetComputeBatch): + @classmethod + def setUpClass(cls): + super().setUpClass() + + def test_01_asset_compute_batch_job(self): + # Confirm 2 assets + self.ict0.validate() + self.assertEqual(self.ict0.depreciation_line_ids[1].amount, 500) + self.vehicle0.validate() + self.assertEqual(self.vehicle0.depreciation_line_ids[1].amount, 2000) + # Compute Asset, with delay + wiz = self._create_compute_wizard(use_batch=True, delay_compute=True) + res = wiz.asset_compute() + batch = self.env["account.asset.compute.batch"].browse(res["res_id"]) + self.assertEqual(batch.state, "draft") + self.assertEqual(batch.depre_amount, 0) + # Batch will be posted by cron job + self.assertFalse(batch.job_state) + batch.with_context(compute_batch_job=1).action_compute_job() + self.assertEqual(batch.job_state, "pending") + # Check queue job should be 1 + action = batch.open_queue_job() + self.assertEqual(action["domain"][0][2], batch.job_current.ids) diff --git a/account_asset_compute_batch_job/views/account_asset_compute_batch.xml b/account_asset_compute_batch_job/views/account_asset_compute_batch.xml new file mode 100644 index 000000000000..f30a278fac50 --- /dev/null +++ b/account_asset_compute_batch_job/views/account_asset_compute_batch.xml @@ -0,0 +1,90 @@ + + + + account.asset.compute.batch.form + account.asset.compute.batch + + + + + {'invisible': [('job_current', '!=', False), '|', ('job_state', 'not in', ['failed', 'cancelled']), ('state', '!=', 'draft')]} + + + + + +