diff --git a/account_asset_batch_compute/README.rst b/account_asset_batch_compute/README.rst new file mode 100644 index 00000000..f683553c --- /dev/null +++ b/account_asset_batch_compute/README.rst @@ -0,0 +1,78 @@ +=========================== +Account Asset Batch Compute +=========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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_batch_compute + :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_batch_compute + :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 in batch. +This module adds a flag on compute assets wizard in order to execute +this process in batch. + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* ACSONE SA/NV +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Adrien Peiffer +* Jordi Ballester Alomar +* Alba Riera + +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_batch_compute/__init__.py b/account_asset_batch_compute/__init__.py new file mode 100644 index 00000000..976591c9 --- /dev/null +++ b/account_asset_batch_compute/__init__.py @@ -0,0 +1,2 @@ +from . import wizards +from . import models diff --git a/account_asset_batch_compute/__manifest__.py b/account_asset_batch_compute/__manifest__.py new file mode 100644 index 00000000..5a57097b --- /dev/null +++ b/account_asset_batch_compute/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2016-2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Account Asset Batch Compute", + "summary": """ + Add the possibility to compute assets in batch""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,ForgeFlow,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-financial-tools", + "depends": ["account_asset_management", "queue_job"], + "data": ["wizards/account_asset_compute_views.xml", "data/queue_data.xml"], +} diff --git a/account_asset_batch_compute/data/queue_data.xml b/account_asset_batch_compute/data/queue_data.xml new file mode 100644 index 00000000..ebb5ca8c --- /dev/null +++ b/account_asset_batch_compute/data/queue_data.xml @@ -0,0 +1,23 @@ + + + + account_asset_batch_compute + + + + + _compute_entries + + + + + asset_compute + + + diff --git a/account_asset_batch_compute/i18n/account_asset_batch_compute.pot b/account_asset_batch_compute/i18n/account_asset_batch_compute.pot new file mode 100644 index 00000000..56b95850 --- /dev/null +++ b/account_asset_batch_compute/i18n/account_asset_batch_compute.pot @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_asset_batch_compute +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_asset_batch_compute +#: model:ir.model,name:account_asset_batch_compute.model_account_asset +msgid "Asset" +msgstr "" + +#. module: account_asset_batch_compute +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset_compute__batch_processing +msgid "Batch Processing" +msgstr "" + +#. module: account_asset_batch_compute +#: model:ir.model,name:account_asset_batch_compute.model_account_asset_compute +msgid "Compute Assets" +msgstr "" + +#. module: account_asset_batch_compute +#: code:addons/account_asset_batch_compute/wizards/account_asset_compute.py:0 +#, python-format +msgid "Creating jobs to create moves for assets to {}" +msgstr "" + +#. module: account_asset_batch_compute +#: code:addons/account_asset_batch_compute/models/account_asset.py:0 +#, python-format +msgid "Creating move for asset with id {rec_id} to {date_end}" +msgstr "" + +#. module: account_asset_batch_compute +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset__display_name +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset_compute__display_name +msgid "Display Name" +msgstr "" + +#. module: account_asset_batch_compute +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset__id +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset_compute__id +msgid "ID" +msgstr "" + +#. module: account_asset_batch_compute +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset____last_update +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset_compute____last_update +msgid "Last Modified on" +msgstr "" diff --git a/account_asset_batch_compute/i18n/es.po b/account_asset_batch_compute/i18n/es.po new file mode 100644 index 00000000..df00ff0b --- /dev/null +++ b/account_asset_batch_compute/i18n/es.po @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_asset_batch_compute +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_asset_batch_compute +#: model:ir.model,name:account_asset_batch_compute.model_account_asset +msgid "Asset" +msgstr "Activo" + +#. module: account_asset_batch_compute +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset_compute__batch_processing +msgid "Batch Processing" +msgstr "Procesamiento por lotes" + +#. module: account_asset_batch_compute +#: model:ir.model,name:account_asset_batch_compute.model_account_asset_compute +msgid "Compute Assets" +msgstr "Calcular activos" + +#. module: account_asset_batch_compute +#: code:addons/account_asset_batch_compute/wizards/account_asset_compute.py:0 +#, python-format +msgid "Creating jobs to create moves for assets to {}" +msgstr "Creando trabajos para crear movimientos de activos a {}" + +#. module: account_asset_batch_compute +#: code:addons/account_asset_batch_compute/models/account_asset.py:0 +#, python-format +msgid "Creating move for asset with id {rec_id} to {date_end}" +msgstr "Creando movimiento de activo con id {rec_id} a {date_end}" + +#. module: account_asset_batch_compute +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset__display_name +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset_compute__display_name +msgid "Display Name" +msgstr "Nombre a mostrar" + +#. module: account_asset_batch_compute +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset__id +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset_compute__id +msgid "ID" +msgstr "ID" + +#. module: account_asset_batch_compute +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset____last_update +#: model:ir.model.fields,field_description:account_asset_batch_compute.field_account_asset_compute____last_update +msgid "Last Modified on" +msgstr "Última modificación en" diff --git a/account_asset_batch_compute/models/__init__.py b/account_asset_batch_compute/models/__init__.py new file mode 100644 index 00000000..02a692c6 --- /dev/null +++ b/account_asset_batch_compute/models/__init__.py @@ -0,0 +1 @@ +from . import account_asset diff --git a/account_asset_batch_compute/models/account_asset.py b/account_asset_batch_compute/models/account_asset.py new file mode 100644 index 00000000..3adb641c --- /dev/null +++ b/account_asset_batch_compute/models/account_asset.py @@ -0,0 +1,31 @@ +# Copyright 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, models + + +class AccountAsset(models.Model): + + _inherit = "account.asset" + + def _compute_entries(self, date_end, check_triggers=False): + if self.env.context.get( + "asset_batch_processing", False + ) and not self.env.context.get("test_queue_job_no_delay", False): + results = [] + log_error = "" + for record in self: + description = _( + "Creating move for asset with id {rec_id} to {date_end}" + ).format( + rec_id=record.id, + date_end=date_end, + ) + record.with_delay(description=description)._compute_entries( + date_end, check_triggers=check_triggers + ) + return results, log_error + else: + return super(AccountAsset, self)._compute_entries( + date_end, check_triggers=check_triggers + ) diff --git a/account_asset_batch_compute/readme/CONTRIBUTORS.rst b/account_asset_batch_compute/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..13321599 --- /dev/null +++ b/account_asset_batch_compute/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Adrien Peiffer +* Jordi Ballester Alomar +* Alba Riera diff --git a/account_asset_batch_compute/readme/DESCRIPTION.rst b/account_asset_batch_compute/readme/DESCRIPTION.rst new file mode 100644 index 00000000..5aaac48e --- /dev/null +++ b/account_asset_batch_compute/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +Add the possibility to compute assets in batch. +This module adds a flag on compute assets wizard in order to execute +this process in batch. diff --git a/account_asset_batch_compute/static/description/icon.svg b/account_asset_batch_compute/static/description/icon.svg new file mode 100644 index 00000000..a7a26d09 --- /dev/null +++ b/account_asset_batch_compute/static/description/icon.svg @@ -0,0 +1,79 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/account_asset_batch_compute/static/description/index.html b/account_asset_batch_compute/static/description/index.html new file mode 100644 index 00000000..15c03ea0 --- /dev/null +++ b/account_asset_batch_compute/static/description/index.html @@ -0,0 +1,424 @@ + + + + + + +Account Asset Batch Compute + + + +
+

Account Asset Batch Compute

+ + +

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

+

Add the possibility to compute assets in batch. +This module adds a flag on compute assets wizard in order to execute +this process in batch.

+

Table of contents

+ +
+

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

+
    +
  • ACSONE SA/NV
  • +
  • ForgeFlow
  • +
+
+
+

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_batch_compute/tests/__init__.py b/account_asset_batch_compute/tests/__init__.py new file mode 100644 index 00000000..a1df8820 --- /dev/null +++ b/account_asset_batch_compute/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_asset_batch_compute diff --git a/account_asset_batch_compute/tests/test_account_asset_batch_compute.py b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py new file mode 100644 index 00000000..5d97f3f3 --- /dev/null +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -0,0 +1,139 @@ +# Copyright 2016-19 ACSONE SA/NV +# Copyright 2019 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import time +from datetime import date + +from dateutil import relativedelta + +from odoo.tests.common import TransactionCase + +from odoo.addons.queue_job.job import Job + + +class TestAccountAssetBatchCompute(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.wiz_obj = cls.env["account.asset.compute"] + cls.asset_model = cls.env["account.asset"] + cls.asset_profile_model = cls.env["account.asset.profile"] + cls.account = cls.env["account.account"].create( + { + "name": "Test account", + "code": "TAC", + "account_type": "liability_payable", + } + ) + cls.journal = cls.env["account.journal"].create( + {"name": "Test Journal", "code": "TJ", "type": "general"} + ) + cls.profile = cls.asset_profile_model.create( + { + "account_expense_depreciation_id": cls.account.id, + "account_asset_id": cls.account.id, + "account_depreciation_id": cls.account.id, + "journal_id": cls.journal.id, + "name": "Test", + } + ) + cls.asset01 = cls.asset_model.create( + { + "name": "test asset", + "profile_id": cls.profile.id, + "purchase_value": 1000, + "salvage_value": 0, + "date_start": time.strftime("2003-01-01"), + "method_time": "year", + "method_number": 1, + "method_period": "month", + "prorata": False, + } + ) + today = date.today() + first_day_of_month = date(today.year, today.month, 1) + cls.nextmonth = first_day_of_month + relativedelta.relativedelta(months=1) + cls.asset01.date_start = first_day_of_month + + def test_no_batch_processing(self): + wiz = self.wiz_obj.create( + {"batch_processing": False, "date_end": self.nextmonth} + ) + # I check if this asset is draft + self.assertEqual(self.asset01.state, "draft") + # I confirm this asset + self.asset01.validate() + # I check if this asset is running + self.assertEqual(self.asset01.state, "open") + self.asset01.compute_depreciation_board() + # I check that there is no depreciation line + depreciation_line = self.asset01.depreciation_line_ids.filtered( + lambda r: r.type == "depreciate" and r.move_id + ) + self.assertTrue(len(depreciation_line) == 0) + wiz.asset_compute() + depreciation_line = self.asset01.depreciation_line_ids.filtered( + lambda r: r.type == "depreciate" and r.move_id + ) + self.assertTrue(len(depreciation_line) == 1) + + def test_batch_processing(self): + wiz = self.wiz_obj.create( + {"batch_processing": True, "date_end": self.nextmonth} + ) + # I check if this asset is draft + self.assertEqual(self.asset01.state, "draft") + # I confirm this asset + self.asset01.validate() + # I check if this asset is running + self.assertEqual(self.asset01.state, "open") + self.asset01.compute_depreciation_board() + # I check that there is no depreciation line + depreciation_line = self.asset01.depreciation_line_ids.filtered( + lambda r: r.type == "depreciate" and r.move_id + ) + self.assertTrue(len(depreciation_line) == 0) + wiz.with_context(test_queue_job_no_delay=False).asset_compute() + depreciation_line = self.asset01.depreciation_line_ids.filtered( + lambda r: r.type == "depreciate" and r.move_id + ) + self.assertTrue(len(depreciation_line) == 0) + job_name = "Creating jobs to create moves for assets to %s" % (self.nextmonth) + jobs = self.env["queue.job"].search( + [("name", "=", job_name)], order="date_created desc", limit=1 + ) + self.assertEqual( + jobs.job_function_id, + self.env.ref( + "account_asset_batch_compute." + "job_function_account_asset_compute_asset_compute" + ), + ) + self.assertTrue(len(jobs) == 1) + job = Job.load(self.env, jobs.uuid) + # perform job + job.perform() + depreciation_line = self.asset01.depreciation_line_ids.filtered( + lambda r: r.type == "depreciate" and r.move_id + ) + self.assertTrue(len(depreciation_line) == 0) + job_name = "Creating move for asset with id {} to {}".format( + self.asset01.id, + self.nextmonth, + ) + jobs = self.env["queue.job"].search( + [("name", "=", job_name)], order="date_created desc", limit=1 + ) + self.assertTrue(len(jobs) == 1) + self.assertEqual( + jobs.job_function_id, + self.env.ref( + "account_asset_batch_compute.job_function_account_asset_compute_entries" + ), + ) + job = Job.load(self.env, jobs.uuid) + job.perform() + depreciation_line = self.asset01.depreciation_line_ids.filtered( + lambda r: r.type == "depreciate" and r.move_id + ) + self.assertEqual(len(depreciation_line), 1) diff --git a/account_asset_batch_compute/wizards/__init__.py b/account_asset_batch_compute/wizards/__init__.py new file mode 100644 index 00000000..07bfe6b3 --- /dev/null +++ b/account_asset_batch_compute/wizards/__init__.py @@ -0,0 +1 @@ +from . import account_asset_compute diff --git a/account_asset_batch_compute/wizards/account_asset_compute.py b/account_asset_batch_compute/wizards/account_asset_compute.py new file mode 100644 index 00000000..4befec1a --- /dev/null +++ b/account_asset_batch_compute/wizards/account_asset_compute.py @@ -0,0 +1,28 @@ +# Copyright 2016-2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, fields, models + + +class AccountAssetCompute(models.TransientModel): + + _inherit = "account.asset.compute" + + batch_processing = fields.Boolean() + + def asset_compute(self): + self.ensure_one() + if not self.batch_processing: + return super().asset_compute() + 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 {}").format( + self.date_end, + ) + job = self.with_delay(description=description).asset_compute() + return "Job created with uuid {}".format(job.uuid) + else: + return super( + AccountAssetCompute, self.with_context(asset_batch_processing=True) + ).asset_compute() diff --git a/account_asset_batch_compute/wizards/account_asset_compute_views.xml b/account_asset_batch_compute/wizards/account_asset_compute_views.xml new file mode 100644 index 00000000..8c882b3c --- /dev/null +++ b/account_asset_batch_compute/wizards/account_asset_compute_views.xml @@ -0,0 +1,20 @@ + + + + + account.asset.compute (in account_asset_batch_compute) + account.asset.compute + + + + + + + + diff --git a/setup/account_asset_batch_compute/odoo/addons/account_asset_batch_compute b/setup/account_asset_batch_compute/odoo/addons/account_asset_batch_compute new file mode 120000 index 00000000..6ff71b28 --- /dev/null +++ b/setup/account_asset_batch_compute/odoo/addons/account_asset_batch_compute @@ -0,0 +1 @@ +../../../../account_asset_batch_compute \ No newline at end of file diff --git a/setup/account_asset_batch_compute/setup.py b/setup/account_asset_batch_compute/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_asset_batch_compute/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)