From 6de28a97bc56b55c5e29001694149e3d7121bb5b Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Thu, 25 Aug 2016 15:26:49 +0200 Subject: [PATCH 01/13] Add account_asset_batch_compute --- account_asset_batch_compute/README.rst | 57 +++++++++++++ account_asset_batch_compute/__init__.py | 2 + account_asset_batch_compute/__openerp__.py | 20 +++++ .../models/__init__.py | 1 + .../models/account_asset_asset.py | 48 +++++++++++ .../static/description/icon.svg | 79 +++++++++++++++++++ account_asset_batch_compute/tests/__init__.py | 1 + .../tests/test_account_asset_batch_compute.py | 67 ++++++++++++++++ .../wizards/__init__.py | 1 + .../asset_depreciation_confirmation_wizard.py | 51 ++++++++++++ ...asset_depreciation_confirmation_wizard.xml | 20 +++++ 11 files changed, 347 insertions(+) create mode 100644 account_asset_batch_compute/README.rst create mode 100644 account_asset_batch_compute/__init__.py create mode 100644 account_asset_batch_compute/__openerp__.py create mode 100644 account_asset_batch_compute/models/__init__.py create mode 100644 account_asset_batch_compute/models/account_asset_asset.py create mode 100644 account_asset_batch_compute/static/description/icon.svg create mode 100644 account_asset_batch_compute/tests/__init__.py create mode 100644 account_asset_batch_compute/tests/test_account_asset_batch_compute.py create mode 100644 account_asset_batch_compute/wizards/__init__.py create mode 100644 account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.py create mode 100644 account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml diff --git a/account_asset_batch_compute/README.rst b/account_asset_batch_compute/README.rst new file mode 100644 index 000000000..cc575532e --- /dev/null +++ b/account_asset_batch_compute/README.rst @@ -0,0 +1,57 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +====================================== +Account Asset Batch Compute +====================================== + +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. + + +Usage +===== + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/92/8.0 + + + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Adrien Peiffer + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/account_asset_batch_compute/__init__.py b/account_asset_batch_compute/__init__.py new file mode 100644 index 000000000..976591c99 --- /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/__openerp__.py b/account_asset_batch_compute/__openerp__.py new file mode 100644 index 000000000..c3cd5d454 --- /dev/null +++ b/account_asset_batch_compute/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 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': '8.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', + 'website': 'www.acsone.eu', + 'depends': [ + 'account_asset_management', + 'connector', + ], + 'data': [ + 'wizards/asset_depreciation_confirmation_wizard.xml', + ], +} diff --git a/account_asset_batch_compute/models/__init__.py b/account_asset_batch_compute/models/__init__.py new file mode 100644 index 000000000..4e8f0c987 --- /dev/null +++ b/account_asset_batch_compute/models/__init__.py @@ -0,0 +1 @@ +from . import account_asset_asset diff --git a/account_asset_batch_compute/models/account_asset_asset.py b/account_asset_batch_compute/models/account_asset_asset.py new file mode 100644 index 000000000..b108b919b --- /dev/null +++ b/account_asset_batch_compute/models/account_asset_asset.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import api, models, _ + +import logging +_logger = logging.getLogger(__name__) + +try: + from openerp.addons.connector.session import ConnectorSession + from openerp.addons.connector.queue.job import job +except ImportError: + _logger.debug('Can not `import connector`.') + + def empty_decorator(func): + return func + job = empty_decorator + + +class AccountAssetAsset(models.Model): + + _inherit = 'account.asset.asset' + + @api.multi + def _compute_entries(self, period_id, check_triggers=False): + if self.env.context.get('asset_batch_processing'): + for record in self: + session = ConnectorSession.from_env(self.env) + description =\ + _("Creating move for asset with id %s on period %s") %\ + (record.id, period_id) + async_compute_entries.delay( + session, record.id, period_id, + check_triggers=check_triggers, description=description) + return [] + else: + self.env.context = self.env.context.copy() + return super(AccountAssetAsset, self)._compute_entries( + period_id, check_triggers=check_triggers) + + +@job(default_channel='root.account_asset_batch_compute') +def async_compute_entries(session, asset_id, period_id, + check_triggers=False): + asset = session.env['account.asset.asset'].browse([asset_id])[0] + asset.with_context(asset_batch_processing=False)\ + ._compute_entries(period_id, check_triggers=check_triggers) 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 000000000..a7a26d093 --- /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/tests/__init__.py b/account_asset_batch_compute/tests/__init__.py new file mode 100644 index 000000000..a1df88209 --- /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 000000000..1380f9f13 --- /dev/null +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests.common import TransactionCase +from openerp.addons.connector.tests.common import mock_job_delay_to_direct +from datetime import date + +DELAY2 = ('openerp.addons.account_asset_batch_compute.wizards.' + 'asset_depreciation_confirmation_wizard.async_asset_compute') +DELAY1 = ('openerp.addons.account_asset_batch_compute.models.' + 'account_asset_asset.async_compute_entries') + + +class TestAccountAssetBatchCompute(TransactionCase): + + def setUp(self): + super(TestAccountAssetBatchCompute, self).setUp() + self.wiz_obj = self.env['asset.depreciation.confirmation.wizard'] + self.asset01 = self.env.ref( + 'account_asset_management.account_asset_asset_ict0') + self.asset01.method_period = 'month' + today = date.today() + first_day_of_month = date(today.year, today.month, 1) + self.asset01.date_start = first_day_of_month + + def test_1(self): + period = self.env['account.period'].find() + wiz = self.wiz_obj.create({'batch_processing': False, + 'period_id': period.id}) + # 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_2(self): + period = self.env['account.period'].find() + wiz = self.wiz_obj.create({'batch_processing': True, + 'period_id': period.id}) + # 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) + with mock_job_delay_to_direct(DELAY1),\ + mock_job_delay_to_direct(DELAY2): + 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) diff --git a/account_asset_batch_compute/wizards/__init__.py b/account_asset_batch_compute/wizards/__init__.py new file mode 100644 index 000000000..15770f31e --- /dev/null +++ b/account_asset_batch_compute/wizards/__init__.py @@ -0,0 +1 @@ +from . import asset_depreciation_confirmation_wizard diff --git a/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.py b/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.py new file mode 100644 index 000000000..1c7702cac --- /dev/null +++ b/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import api, fields, models, _ + +import logging +_logger = logging.getLogger(__name__) + +try: + from openerp.addons.connector.session import ConnectorSession + from openerp.addons.connector.queue.job import job +except ImportError: + _logger.debug('Can not `import connector`.') + + def empty_decorator(func): + return func + job = empty_decorator + + +class AssetDepreciationConfirmationWizard(models.TransientModel): + + _inherit = 'asset.depreciation.confirmation.wizard' + + batch_processing = fields.Boolean() + + @api.multi + def asset_compute(self): + self.ensure_one() + if not self.batch_processing: + return super(AssetDepreciationConfirmationWizard, self)\ + .asset_compute() + if self.env.context.get('not_async'): + return super(AssetDepreciationConfirmationWizard, + self.with_context(asset_batch_processing=True))\ + .asset_compute() + else: + session = ConnectorSession.from_env(self.env) + description =\ + _("Creating jobs to create moves for assets period %s") % ( + self.period_id.id,) + async_asset_compute.delay(session, self.period_id.id, + description=description) + + +@job(default_channel='root.account_asset_batch_compute') +def async_asset_compute(session, period_id): + model = session.env['asset.depreciation.confirmation.wizard'] + obj = model.create({'period_id': period_id, + 'batch_processing': True}) + obj.with_context(not_async=True).asset_compute() diff --git a/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml b/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml new file mode 100644 index 000000000..aaddde9d8 --- /dev/null +++ b/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml @@ -0,0 +1,20 @@ + + + + + + + + asset.depreciation.confirmation.wizard.form (in account_asset_batch_compute) + asset.depreciation.confirmation.wizard + + + + + + + + + + From 86d5c55b06fdd26d4e8f316b805cd48b81a6452b Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Thu, 23 Mar 2017 07:52:07 +0100 Subject: [PATCH 02/13] [MIG] Migration of account_asset_batch_compute --- account_asset_batch_compute/README.rst | 6 +- .../{__openerp__.py => __manifest__.py} | 6 +- .../models/__init__.py | 2 +- .../models/account_asset.py | 37 ++++++++++++ .../models/account_asset_asset.py | 48 ---------------- .../tests/test_account_asset_batch_compute.py | 57 ++++++++++++++----- .../asset_depreciation_confirmation_wizard.py | 35 +++++------- ...asset_depreciation_confirmation_wizard.xml | 2 +- 8 files changed, 100 insertions(+), 93 deletions(-) rename account_asset_batch_compute/{__openerp__.py => __manifest__.py} (84%) create mode 100644 account_asset_batch_compute/models/account_asset.py delete mode 100644 account_asset_batch_compute/models/account_asset_asset.py diff --git a/account_asset_batch_compute/README.rst b/account_asset_batch_compute/README.rst index cc575532e..76198cb39 100644 --- a/account_asset_batch_compute/README.rst +++ b/account_asset_batch_compute/README.rst @@ -9,16 +9,12 @@ Account Asset Batch Compute 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. - Usage ===== - .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/92/8.0 - - + :target: https://runbot.odoo-community.org/runbot/92/10.0 Bug Tracker =========== diff --git a/account_asset_batch_compute/__openerp__.py b/account_asset_batch_compute/__manifest__.py similarity index 84% rename from account_asset_batch_compute/__openerp__.py rename to account_asset_batch_compute/__manifest__.py index c3cd5d454..d6a4ccbb3 100644 --- a/account_asset_batch_compute/__openerp__.py +++ b/account_asset_batch_compute/__manifest__.py @@ -1,18 +1,18 @@ # -*- coding: utf-8 -*- -# Copyright 2016 ACSONE SA/NV +# 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': '8.0.1.0.0', + 'version': '10.0.1.0.0', 'license': 'AGPL-3', 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', 'website': 'www.acsone.eu', 'depends': [ 'account_asset_management', - 'connector', + 'queue_job', ], 'data': [ 'wizards/asset_depreciation_confirmation_wizard.xml', diff --git a/account_asset_batch_compute/models/__init__.py b/account_asset_batch_compute/models/__init__.py index 4e8f0c987..8be8e8ae5 100644 --- a/account_asset_batch_compute/models/__init__.py +++ b/account_asset_batch_compute/models/__init__.py @@ -1 +1 @@ -from . import account_asset_asset +from . import account_asset \ No newline at end of file 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 000000000..743cebab4 --- /dev/null +++ b/account_asset_batch_compute/models/account_asset.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import api, models, _ + +import logging +_logger = logging.getLogger(__name__) + +try: + from odoo.addons.queue_job.job import job +except ImportError: + _logger.debug('Can not `import queue_job`.') + + def empty_decorator(func): + return func + job = empty_decorator + + +class AccountAsset(models.Model): + + _inherit = 'account.asset' + + @api.multi + @job(default_channel='root.account_asset_batch_compute') + def _compute_entries(self, date_end, check_triggers=False): + if self.env.context.get('asset_batch_processing'): + for record in self: + description =\ + _("Creating move for asset with id %s to %s") %\ + (record.id, date_end) + record.with_delay(description=description)._compute_entries( + date_end, check_triggers=check_triggers) + return [] + else: + return super(AccountAsset, self)._compute_entries( + date_end, check_triggers=check_triggers) diff --git a/account_asset_batch_compute/models/account_asset_asset.py b/account_asset_batch_compute/models/account_asset_asset.py deleted file mode 100644 index b108b919b..000000000 --- a/account_asset_batch_compute/models/account_asset_asset.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2016 ACSONE SA/NV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from openerp import api, models, _ - -import logging -_logger = logging.getLogger(__name__) - -try: - from openerp.addons.connector.session import ConnectorSession - from openerp.addons.connector.queue.job import job -except ImportError: - _logger.debug('Can not `import connector`.') - - def empty_decorator(func): - return func - job = empty_decorator - - -class AccountAssetAsset(models.Model): - - _inherit = 'account.asset.asset' - - @api.multi - def _compute_entries(self, period_id, check_triggers=False): - if self.env.context.get('asset_batch_processing'): - for record in self: - session = ConnectorSession.from_env(self.env) - description =\ - _("Creating move for asset with id %s on period %s") %\ - (record.id, period_id) - async_compute_entries.delay( - session, record.id, period_id, - check_triggers=check_triggers, description=description) - return [] - else: - self.env.context = self.env.context.copy() - return super(AccountAssetAsset, self)._compute_entries( - period_id, check_triggers=check_triggers) - - -@job(default_channel='root.account_asset_batch_compute') -def async_compute_entries(session, asset_id, period_id, - check_triggers=False): - asset = session.env['account.asset.asset'].browse([asset_id])[0] - asset.with_context(asset_batch_processing=False)\ - ._compute_entries(period_id, check_triggers=check_triggers) 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 index 1380f9f13..73e38636c 100644 --- a/account_asset_batch_compute/tests/test_account_asset_batch_compute.py +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -2,32 +2,50 @@ # Copyright 2016 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp.tests.common import TransactionCase -from openerp.addons.connector.tests.common import mock_job_delay_to_direct +from odoo import tools +from odoo.modules.module import get_resource_path + +from odoo.tests.common import TransactionCase from datetime import date -DELAY2 = ('openerp.addons.account_asset_batch_compute.wizards.' +from dateutil import relativedelta + +from odoo.addons.queue_job.job import Job + +DELAY2 = ('odoo.addons.account_asset_batch_compute.wizards.' 'asset_depreciation_confirmation_wizard.async_asset_compute') -DELAY1 = ('openerp.addons.account_asset_batch_compute.models.' +DELAY1 = ('odoo.addons.account_asset_batch_compute.models.' 'account_asset_asset.async_compute_entries') class TestAccountAssetBatchCompute(TransactionCase): + def _load(self, module, *args): + tools.convert_file(self.cr, module, + get_resource_path(module, *args), + {}, 'init', False, 'test', + self.registry._assertion_report) + def setUp(self): super(TestAccountAssetBatchCompute, self).setUp() + self._load('account', 'test', 'account_minimal_test.xml') + self._load('account_asset_management', 'demo', + 'account_asset_demo.xml') self.wiz_obj = self.env['asset.depreciation.confirmation.wizard'] self.asset01 = self.env.ref( - 'account_asset_management.account_asset_asset_ict0') + 'account_asset_management.account_asset_ict0') self.asset01.method_period = 'month' today = date.today() first_day_of_month = date(today.year, today.month, 1) + self.nextmonth =\ + first_day_of_month + relativedelta.relativedelta(months=1) + self.nextmonth = first_day_of_month + relativedelta.relativedelta( + months=1) self.asset01.date_start = first_day_of_month def test_1(self): - period = self.env['account.period'].find() wiz = self.wiz_obj.create({'batch_processing': False, - 'period_id': period.id}) + 'date_end': self.nextmonth}) # I check if this asset is draft self.assertEqual(self.asset01.state, 'draft') # I confirm this asset @@ -45,9 +63,8 @@ class TestAccountAssetBatchCompute(TransactionCase): self.assertTrue(len(depreciation_line) == 1) def test_2(self): - period = self.env['account.period'].find() wiz = self.wiz_obj.create({'batch_processing': True, - 'period_id': period.id}) + 'date_end': self.nextmonth}) # I check if this asset is draft self.assertEqual(self.asset01.state, 'draft') # I confirm this asset @@ -59,9 +76,23 @@ class TestAccountAssetBatchCompute(TransactionCase): depreciation_line = self.asset01.depreciation_line_ids\ .filtered(lambda r: r.type == 'depreciate' and r.move_id) self.assertTrue(len(depreciation_line) == 0) - with mock_job_delay_to_direct(DELAY1),\ - mock_job_delay_to_direct(DELAY2): - wiz.asset_compute() - depreciation_line = self.asset01.depreciation_line_ids\ + 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) == 0) + jobs = self.env['queue.job'].search( + [], order='date_created desc', limit=1) + self.assertTrue(len(jobs) == 1) + 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.assertTrue(len(depreciation_line) == 0) + jobs = self.env['queue.job'].search( + [], order='date_created desc', limit=1) + self.assertTrue(len(jobs) == 1) + 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.assertTrue(len(depreciation_line) == 1) diff --git a/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.py b/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.py index 1c7702cac..455319beb 100644 --- a/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.py +++ b/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2016 ACSONE SA/NV +# Copyright 2016-2017 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import api, fields, models, _ @@ -8,10 +8,9 @@ import logging _logger = logging.getLogger(__name__) try: - from openerp.addons.connector.session import ConnectorSession - from openerp.addons.connector.queue.job import job + from odoo.addons.queue_job.job import job except ImportError: - _logger.debug('Can not `import connector`.') + _logger.debug('Can not `import queue_job`.') def empty_decorator(func): return func @@ -25,27 +24,19 @@ class AssetDepreciationConfirmationWizard(models.TransientModel): batch_processing = fields.Boolean() @api.multi + @job(default_channel='root.account_asset_batch_compute') def asset_compute(self): self.ensure_one() if not self.batch_processing: return super(AssetDepreciationConfirmationWizard, self)\ .asset_compute() - if self.env.context.get('not_async'): - return super(AssetDepreciationConfirmationWizard, - self.with_context(asset_batch_processing=True))\ - .asset_compute() + if not self.env.context.get('job_uuid'): + description = \ + _("Creating jobs to create moves for assets to %s") % ( + self.date_end,) + job = self.with_delay(description=description).asset_compute() + return u'Job created with uuid %s' % (job.uuid,) else: - session = ConnectorSession.from_env(self.env) - description =\ - _("Creating jobs to create moves for assets period %s") % ( - self.period_id.id,) - async_asset_compute.delay(session, self.period_id.id, - description=description) - - -@job(default_channel='root.account_asset_batch_compute') -def async_asset_compute(session, period_id): - model = session.env['asset.depreciation.confirmation.wizard'] - obj = model.create({'period_id': period_id, - 'batch_processing': True}) - obj.with_context(not_async=True).asset_compute() + self = self.with_context(asset_batch_processing=True) + return super(AssetDepreciationConfirmationWizard, self)\ + .asset_compute() diff --git a/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml b/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml index aaddde9d8..a2c4f44eb 100644 --- a/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml +++ b/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml @@ -10,7 +10,7 @@ asset.depreciation.confirmation.wizard - + From dee91f6e164360cda8bce5bf59fd2475feafd594 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Thu, 31 Oct 2019 07:20:20 +0100 Subject: [PATCH 03/13] migrate account_asset_batch_compute --- account_asset_batch_compute/README.rst | 53 --------- account_asset_batch_compute/__manifest__.py | 9 +- .../models/account_asset.py | 16 ++- .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 4 + .../tests/test_account_asset_batch_compute.py | 103 ++++++++++++------ .../wizards/__init__.py | 2 +- ...ion_wizard.py => account_asset_compute.py} | 20 ++-- .../wizards/account_asset_compute_views.xml | 20 ++++ ...asset_depreciation_confirmation_wizard.xml | 20 ---- 10 files changed, 116 insertions(+), 133 deletions(-) delete mode 100644 account_asset_batch_compute/README.rst create mode 100644 account_asset_batch_compute/readme/CONTRIBUTORS.rst create mode 100644 account_asset_batch_compute/readme/DESCRIPTION.rst rename account_asset_batch_compute/wizards/{asset_depreciation_confirmation_wizard.py => account_asset_compute.py} (60%) create mode 100644 account_asset_batch_compute/wizards/account_asset_compute_views.xml delete mode 100644 account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml diff --git a/account_asset_batch_compute/README.rst b/account_asset_batch_compute/README.rst deleted file mode 100644 index 76198cb39..000000000 --- a/account_asset_batch_compute/README.rst +++ /dev/null @@ -1,53 +0,0 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 - -====================================== -Account Asset Batch Compute -====================================== - -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. - -Usage -===== - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/92/10.0 - -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. - -Credits -======= - -Images ------- - -* Odoo Community Association: `Icon `_. - -Contributors ------------- - -* Adrien Peiffer - -Maintainer ----------- - -.. image:: https://odoo-community.org/logo.png - :alt: Odoo Community Association - :target: https://odoo-community.org - -This module is maintained by the OCA. - -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. - -To contribute to this module, please visit https://odoo-community.org. diff --git a/account_asset_batch_compute/__manifest__.py b/account_asset_batch_compute/__manifest__.py index d6a4ccbb3..f854c72ef 100644 --- a/account_asset_batch_compute/__manifest__.py +++ b/account_asset_batch_compute/__manifest__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016-2017 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -6,15 +5,17 @@ 'name': 'Account Asset Batch Compute', 'summary': """ Add the possibility to compute assets in batch""", - 'version': '10.0.1.0.0', + 'version': '11.0.1.0.0', 'license': 'AGPL-3', - 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', + 'author': 'ACSONE SA/NV,' + 'Eficent,' + 'Odoo Community Association (OCA)', 'website': 'www.acsone.eu', 'depends': [ 'account_asset_management', 'queue_job', ], 'data': [ - 'wizards/asset_depreciation_confirmation_wizard.xml', + 'wizards/account_asset_compute_views.xml', ], } diff --git a/account_asset_batch_compute/models/account_asset.py b/account_asset_batch_compute/models/account_asset.py index 743cebab4..a85536014 100644 --- a/account_asset_batch_compute/models/account_asset.py +++ b/account_asset_batch_compute/models/account_asset.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- # Copyright 2016 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import api, models, _ +from odoo import api, models, _ import logging _logger = logging.getLogger(__name__) @@ -12,10 +11,6 @@ try: except ImportError: _logger.debug('Can not `import queue_job`.') - def empty_decorator(func): - return func - job = empty_decorator - class AccountAsset(models.Model): @@ -24,14 +19,17 @@ class AccountAsset(models.Model): @api.multi @job(default_channel='root.account_asset_batch_compute') def _compute_entries(self, date_end, check_triggers=False): - if self.env.context.get('asset_batch_processing'): + if self.env.context.get('asset_batch_processing', False): + results = [] + log_error = '' for record in self: description =\ _("Creating move for asset with id %s to %s") %\ (record.id, date_end) - record.with_delay(description=description)._compute_entries( + record.with_delay( + description=description)._compute_entries( date_end, check_triggers=check_triggers) - return [] + 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 000000000..615367e6f --- /dev/null +++ b/account_asset_batch_compute/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Adrien Peiffer +* Jordi Ballester Alomar diff --git a/account_asset_batch_compute/readme/DESCRIPTION.rst b/account_asset_batch_compute/readme/DESCRIPTION.rst new file mode 100644 index 000000000..598f9c666 --- /dev/null +++ b/account_asset_batch_compute/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +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/tests/test_account_asset_batch_compute.py b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py index 73e38636c..f5d272652 100644 --- a/account_asset_batch_compute/tests/test_account_asset_batch_compute.py +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -1,40 +1,72 @@ -# -*- coding: utf-8 -*- -# Copyright 2016 ACSONE SA/NV +# Copyright 2016-19 ACSONE SA/NV +# Copyright 2019 Eficent Business and IT Consulting Services, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo import tools -from odoo.modules.module import get_resource_path - +import time from odoo.tests.common import TransactionCase from datetime import date - from dateutil import relativedelta from odoo.addons.queue_job.job import Job DELAY2 = ('odoo.addons.account_asset_batch_compute.wizards.' - 'asset_depreciation_confirmation_wizard.async_asset_compute') + 'account_asset_compute.async_asset_compute') DELAY1 = ('odoo.addons.account_asset_batch_compute.models.' - 'account_asset_asset.async_compute_entries') + 'account_asset.async_compute_entries') class TestAccountAssetBatchCompute(TransactionCase): - def _load(self, module, *args): - tools.convert_file(self.cr, module, - get_resource_path(module, *args), - {}, 'init', False, 'test', - self.registry._assertion_report) - def setUp(self): super(TestAccountAssetBatchCompute, self).setUp() - self._load('account', 'test', 'account_minimal_test.xml') - self._load('account_asset_management', 'demo', - 'account_asset_demo.xml') - self.wiz_obj = self.env['asset.depreciation.confirmation.wizard'] - self.asset01 = self.env.ref( - 'account_asset_management.account_asset_ict0') - self.asset01.method_period = 'month' + self.wiz_obj = self.env['account.asset.compute'] + self.asset_model = self.env['account.asset'] + self.asset_profile_model = self.env['account.asset.profile'] + self.account_account_type_model = self.env['account.account.type'] + self.account_type_regular = self.account_account_type_model.create({ + 'name': 'Test Regular', + 'type': 'other', + }) + self.view_asset = self.asset_model.create({ + 'type': 'view', + 'state': 'open', + 'name': 'view', + 'purchase_value': 0.0, + }) + self.account = self.env['account.account'].create({ + 'name': 'Test account', + 'code': 'TAC', + 'user_type_id': self.account_type_regular.id, + }) + self.journal = self.env['account.journal'].create({ + 'name': 'Test Journal', + 'code': 'TJ', + 'type': 'general', + }) + self.profile = self.asset_profile_model.create({ + 'parent_id': self.view_asset.id, + 'account_expense_depreciation_id': self.account.id, + 'account_asset_id': self.account.id, + 'account_depreciation_id': self.account.id, + 'journal_id': self.journal.id, + 'name': "Test", + }) + self.fiscal_year = self.env['date.range'].create({ + 'type_id': self.ref('account_fiscal_year.fiscalyear'), + 'name': 'FY', + 'date_start': time.strftime('2019-01-01'), + 'date_end': time.strftime('2019-12-31'), + }) + self.asset01 = self.asset_model.create({ + 'name': 'test asset', + 'profile_id': self.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) self.nextmonth =\ @@ -76,23 +108,28 @@ class TestAccountAssetBatchCompute(TransactionCase): 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() + wiz.with_context(test_queue_job_no_delay=True).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( - [], order='date_created desc', limit=1) + [('name', '=', job_name)], order='date_created desc', limit=1) + 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 %s to %s" % ( + 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) 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.assertTrue(len(depreciation_line) == 0) - jobs = self.env['queue.job'].search( - [], order='date_created desc', limit=1) - self.assertTrue(len(jobs) == 1) - 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.assertTrue(len(depreciation_line) == 1) + self.assertEquals(len(depreciation_line), 1) diff --git a/account_asset_batch_compute/wizards/__init__.py b/account_asset_batch_compute/wizards/__init__.py index 15770f31e..07bfe6b38 100644 --- a/account_asset_batch_compute/wizards/__init__.py +++ b/account_asset_batch_compute/wizards/__init__.py @@ -1 +1 @@ -from . import asset_depreciation_confirmation_wizard +from . import account_asset_compute diff --git a/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.py b/account_asset_batch_compute/wizards/account_asset_compute.py similarity index 60% rename from account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.py rename to account_asset_batch_compute/wizards/account_asset_compute.py index 455319beb..7f5ce389c 100644 --- a/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.py +++ b/account_asset_batch_compute/wizards/account_asset_compute.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- # Copyright 2016-2017 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import api, fields, models, _ +from odoo import api, fields, models, _ import logging _logger = logging.getLogger(__name__) @@ -12,14 +11,10 @@ try: except ImportError: _logger.debug('Can not `import queue_job`.') - def empty_decorator(func): - return func - job = empty_decorator +class AccountAssetCompute(models.TransientModel): -class AssetDepreciationConfirmationWizard(models.TransientModel): - - _inherit = 'asset.depreciation.confirmation.wizard' + _inherit = 'account.asset.compute' batch_processing = fields.Boolean() @@ -28,8 +23,7 @@ class AssetDepreciationConfirmationWizard(models.TransientModel): def asset_compute(self): self.ensure_one() if not self.batch_processing: - return super(AssetDepreciationConfirmationWizard, self)\ - .asset_compute() + return super(AccountAssetCompute, self).asset_compute() if not self.env.context.get('job_uuid'): description = \ _("Creating jobs to create moves for assets to %s") % ( @@ -37,6 +31,6 @@ class AssetDepreciationConfirmationWizard(models.TransientModel): job = self.with_delay(description=description).asset_compute() return u'Job created with uuid %s' % (job.uuid,) else: - self = self.with_context(asset_batch_processing=True) - return super(AssetDepreciationConfirmationWizard, self)\ - .asset_compute() + 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 000000000..91c5d452f --- /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/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml b/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml deleted file mode 100644 index a2c4f44eb..000000000 --- a/account_asset_batch_compute/wizards/asset_depreciation_confirmation_wizard.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - asset.depreciation.confirmation.wizard.form (in account_asset_batch_compute) - asset.depreciation.confirmation.wizard - - - - - - - - - - From ff7611950edad6b6a1a499846e1a45ca1d5d70e8 Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Sun, 3 Nov 2019 22:08:09 +0100 Subject: [PATCH 04/13] [FIX] account_asset_batch_compute: Fixing tests --- account_asset_batch_compute/models/account_asset.py | 4 +++- .../tests/test_account_asset_batch_compute.py | 2 +- account_asset_batch_compute/wizards/account_asset_compute.py | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/account_asset_batch_compute/models/account_asset.py b/account_asset_batch_compute/models/account_asset.py index a85536014..49440fae0 100644 --- a/account_asset_batch_compute/models/account_asset.py +++ b/account_asset_batch_compute/models/account_asset.py @@ -19,7 +19,9 @@ class AccountAsset(models.Model): @api.multi @job(default_channel='root.account_asset_batch_compute') def _compute_entries(self, date_end, check_triggers=False): - if self.env.context.get('asset_batch_processing', 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: 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 index f5d272652..ad091dd61 100644 --- a/account_asset_batch_compute/tests/test_account_asset_batch_compute.py +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -108,7 +108,7 @@ class TestAccountAssetBatchCompute(TransactionCase): 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=True).asset_compute() + 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) diff --git a/account_asset_batch_compute/wizards/account_asset_compute.py b/account_asset_batch_compute/wizards/account_asset_compute.py index 7f5ce389c..bae67dee7 100644 --- a/account_asset_batch_compute/wizards/account_asset_compute.py +++ b/account_asset_batch_compute/wizards/account_asset_compute.py @@ -24,7 +24,9 @@ class AccountAssetCompute(models.TransientModel): self.ensure_one() if not self.batch_processing: return super(AccountAssetCompute, self).asset_compute() - if not self.env.context.get('job_uuid'): + 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,) From 2c1d095b5d4273b56857f9ddc95dc81d5eabf0c5 Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Mon, 9 Mar 2020 11:57:35 +0100 Subject: [PATCH 05/13] [MIG][12.0] account_asset_batch_compute --- account_asset_batch_compute/__manifest__.py | 4 ++-- account_asset_batch_compute/models/__init__.py | 2 +- .../tests/test_account_asset_batch_compute.py | 14 +++----------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/account_asset_batch_compute/__manifest__.py b/account_asset_batch_compute/__manifest__.py index f854c72ef..7aa0d5056 100644 --- a/account_asset_batch_compute/__manifest__.py +++ b/account_asset_batch_compute/__manifest__.py @@ -5,12 +5,12 @@ 'name': 'Account Asset Batch Compute', 'summary': """ Add the possibility to compute assets in batch""", - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'license': 'AGPL-3', 'author': 'ACSONE SA/NV,' 'Eficent,' 'Odoo Community Association (OCA)', - 'website': 'www.acsone.eu', + 'website': 'https://github.com/OCA/account-financial-tools', 'depends': [ 'account_asset_management', 'queue_job', diff --git a/account_asset_batch_compute/models/__init__.py b/account_asset_batch_compute/models/__init__.py index 8be8e8ae5..02a692c62 100644 --- a/account_asset_batch_compute/models/__init__.py +++ b/account_asset_batch_compute/models/__init__.py @@ -1 +1 @@ -from . import account_asset \ No newline at end of file +from . import account_asset 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 index ad091dd61..aef3c6185 100644 --- a/account_asset_batch_compute/tests/test_account_asset_batch_compute.py +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -26,12 +26,6 @@ class TestAccountAssetBatchCompute(TransactionCase): 'name': 'Test Regular', 'type': 'other', }) - self.view_asset = self.asset_model.create({ - 'type': 'view', - 'state': 'open', - 'name': 'view', - 'purchase_value': 0.0, - }) self.account = self.env['account.account'].create({ 'name': 'Test account', 'code': 'TAC', @@ -43,18 +37,16 @@ class TestAccountAssetBatchCompute(TransactionCase): 'type': 'general', }) self.profile = self.asset_profile_model.create({ - 'parent_id': self.view_asset.id, 'account_expense_depreciation_id': self.account.id, 'account_asset_id': self.account.id, 'account_depreciation_id': self.account.id, 'journal_id': self.journal.id, 'name': "Test", }) - self.fiscal_year = self.env['date.range'].create({ - 'type_id': self.ref('account_fiscal_year.fiscalyear'), + self.fiscal_year = self.env['account.fiscal.year'].create({ 'name': 'FY', - 'date_start': time.strftime('2019-01-01'), - 'date_end': time.strftime('2019-12-31'), + 'date_from': time.strftime('2019-01-01'), + 'date_to': time.strftime('2019-12-31'), }) self.asset01 = self.asset_model.create({ 'name': 'test asset', From e4067d6d61ed3f034e2a68bca13f35fc4d7cba08 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Wed, 26 Aug 2020 10:28:05 +0200 Subject: [PATCH 06/13] [FIX] - remove duplicated/useless code --- account_asset_batch_compute/README.rst | 78 ++++ .../i18n/account_asset_batch_compute.pot | 42 ++ .../static/description/index.html | 423 ++++++++++++++++++ .../tests/test_account_asset_batch_compute.py | 7 - .../wizards/account_asset_compute_views.xml | 6 +- 5 files changed, 545 insertions(+), 11 deletions(-) create mode 100644 account_asset_batch_compute/README.rst create mode 100644 account_asset_batch_compute/i18n/account_asset_batch_compute.pot create mode 100644 account_asset_batch_compute/static/description/index.html diff --git a/account_asset_batch_compute/README.rst b/account_asset_batch_compute/README.rst new file mode 100644 index 000000000..fa64141be --- /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/12.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-12-0/account-financial-tools-12-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/12.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 +* Eficent + +Contributors +~~~~~~~~~~~~ + +* Adrien Peiffer +* Jordi Ballester Alomar + +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/i18n/account_asset_batch_compute.pot b/account_asset_batch_compute/i18n/account_asset_batch_compute.pot new file mode 100644 index 000000000..b146524b1 --- /dev/null +++ b/account_asset_batch_compute/i18n/account_asset_batch_compute.pot @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_asset_batch_compute +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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:31 +#, python-format +msgid "Creating jobs to create moves for assets to %s" +msgstr "" + +#. module: account_asset_batch_compute +#: code:addons/account_asset_batch_compute/models/account_asset.py:29 +#, python-format +msgid "Creating move for asset with id %s to %s" +msgstr "" + 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 000000000..716ae194e --- /dev/null +++ b/account_asset_batch_compute/static/description/index.html @@ -0,0 +1,423 @@ + + + + + + +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
  • +
  • Eficent
  • +
+
+
+

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/test_account_asset_batch_compute.py b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py index aef3c6185..68cb95b1c 100644 --- a/account_asset_batch_compute/tests/test_account_asset_batch_compute.py +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -8,11 +8,6 @@ from dateutil import relativedelta from odoo.addons.queue_job.job import Job -DELAY2 = ('odoo.addons.account_asset_batch_compute.wizards.' - 'account_asset_compute.async_asset_compute') -DELAY1 = ('odoo.addons.account_asset_batch_compute.models.' - 'account_asset.async_compute_entries') - class TestAccountAssetBatchCompute(TransactionCase): @@ -61,8 +56,6 @@ class TestAccountAssetBatchCompute(TransactionCase): }) today = date.today() first_day_of_month = date(today.year, today.month, 1) - self.nextmonth =\ - first_day_of_month + relativedelta.relativedelta(months=1) self.nextmonth = first_day_of_month + relativedelta.relativedelta( months=1) self.asset01.date_start = first_day_of_month diff --git a/account_asset_batch_compute/wizards/account_asset_compute_views.xml b/account_asset_batch_compute/wizards/account_asset_compute_views.xml index 91c5d452f..e06181e1a 100644 --- a/account_asset_batch_compute/wizards/account_asset_compute_views.xml +++ b/account_asset_batch_compute/wizards/account_asset_compute_views.xml @@ -2,8 +2,7 @@ - - + account.asset.compute (in account_asset_batch_compute) @@ -16,5 +15,4 @@
- - + From f8eab326e4cff1f653a017e124e51eb8c92834ee Mon Sep 17 00:00:00 2001 From: Alba Riera Date: Mon, 22 Feb 2021 17:48:48 +0100 Subject: [PATCH 07/13] [IMP] account_asset_batch_compute: black,isort,prettier --- account_asset_batch_compute/__manifest__.py | 23 +-- .../models/account_asset.py | 33 ++-- .../readme/DESCRIPTION.rst | 1 - .../tests/test_account_asset_batch_compute.py | 161 ++++++++++-------- .../wizards/account_asset_compute.py | 27 +-- .../wizards/account_asset_compute_views.xml | 14 +- 6 files changed, 136 insertions(+), 123 deletions(-) diff --git a/account_asset_batch_compute/__manifest__.py b/account_asset_batch_compute/__manifest__.py index 7aa0d5056..1b941025e 100644 --- a/account_asset_batch_compute/__manifest__.py +++ b/account_asset_batch_compute/__manifest__.py @@ -2,20 +2,13 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Account Asset Batch Compute', - 'summary': """ + "name": "Account Asset Batch Compute", + "summary": """ Add the possibility to compute assets in batch""", - 'version': '12.0.1.0.0', - 'license': 'AGPL-3', - 'author': 'ACSONE SA/NV,' - 'Eficent,' - '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', - ], + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV," "Eficent," "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",], } diff --git a/account_asset_batch_compute/models/account_asset.py b/account_asset_batch_compute/models/account_asset.py index 49440fae0..4112dcba1 100644 --- a/account_asset_batch_compute/models/account_asset.py +++ b/account_asset_batch_compute/models/account_asset.py @@ -1,37 +1,40 @@ # Copyright 2016 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, models, _ - import logging + +from odoo import _, api, models + _logger = logging.getLogger(__name__) try: from odoo.addons.queue_job.job import job except ImportError: - _logger.debug('Can not `import queue_job`.') + _logger.debug("Can not `import queue_job`.") class AccountAsset(models.Model): - _inherit = 'account.asset' + _inherit = "account.asset" @api.multi - @job(default_channel='root.account_asset_batch_compute') + @job(default_channel="root.account_asset_batch_compute") 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): + "asset_batch_processing", False + ) and not self.env.context.get("test_queue_job_no_delay", False): results = [] - log_error = '' + log_error = "" for record in self: - description =\ - _("Creating move for asset with id %s to %s") %\ - (record.id, date_end) - record.with_delay( - description=description)._compute_entries( - date_end, check_triggers=check_triggers) + description = _("Creating move for asset with id %s to %s") % ( + record.id, + 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) + date_end, check_triggers=check_triggers + ) diff --git a/account_asset_batch_compute/readme/DESCRIPTION.rst b/account_asset_batch_compute/readme/DESCRIPTION.rst index 598f9c666..5aaac48e1 100644 --- a/account_asset_batch_compute/readme/DESCRIPTION.rst +++ b/account_asset_batch_compute/readme/DESCRIPTION.rst @@ -1,4 +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/tests/test_account_asset_batch_compute.py b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py index 68cb95b1c..1ffaa573e 100644 --- a/account_asset_batch_compute/tests/test_account_asset_batch_compute.py +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -2,119 +2,134 @@ # Copyright 2019 Eficent Business and IT Consulting Services, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import time -from odoo.tests.common import TransactionCase 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): - def setUp(self): super(TestAccountAssetBatchCompute, self).setUp() - self.wiz_obj = self.env['account.asset.compute'] - self.asset_model = self.env['account.asset'] - self.asset_profile_model = self.env['account.asset.profile'] - self.account_account_type_model = self.env['account.account.type'] - self.account_type_regular = self.account_account_type_model.create({ - 'name': 'Test Regular', - 'type': 'other', - }) - self.account = self.env['account.account'].create({ - 'name': 'Test account', - 'code': 'TAC', - 'user_type_id': self.account_type_regular.id, - }) - self.journal = self.env['account.journal'].create({ - 'name': 'Test Journal', - 'code': 'TJ', - 'type': 'general', - }) - self.profile = self.asset_profile_model.create({ - 'account_expense_depreciation_id': self.account.id, - 'account_asset_id': self.account.id, - 'account_depreciation_id': self.account.id, - 'journal_id': self.journal.id, - 'name': "Test", - }) - self.fiscal_year = self.env['account.fiscal.year'].create({ - 'name': 'FY', - 'date_from': time.strftime('2019-01-01'), - 'date_to': time.strftime('2019-12-31'), - }) - self.asset01 = self.asset_model.create({ - 'name': 'test asset', - 'profile_id': self.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, - }) + self.wiz_obj = self.env["account.asset.compute"] + self.asset_model = self.env["account.asset"] + self.asset_profile_model = self.env["account.asset.profile"] + self.account_account_type_model = self.env["account.account.type"] + self.account_type_regular = self.account_account_type_model.create( + {"name": "Test Regular", "type": "other",} + ) + self.account = self.env["account.account"].create( + { + "name": "Test account", + "code": "TAC", + "user_type_id": self.account_type_regular.id, + } + ) + self.journal = self.env["account.journal"].create( + {"name": "Test Journal", "code": "TJ", "type": "general",} + ) + self.profile = self.asset_profile_model.create( + { + "account_expense_depreciation_id": self.account.id, + "account_asset_id": self.account.id, + "account_depreciation_id": self.account.id, + "journal_id": self.journal.id, + "name": "Test", + } + ) + self.fiscal_year = self.env["account.fiscal.year"].create( + { + "name": "FY", + "date_from": time.strftime("2019-01-01"), + "date_to": time.strftime("2019-12-31"), + } + ) + self.asset01 = self.asset_model.create( + { + "name": "test asset", + "profile_id": self.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) - self.nextmonth = first_day_of_month + relativedelta.relativedelta( - months=1) + self.nextmonth = first_day_of_month + relativedelta.relativedelta(months=1) self.asset01.date_start = first_day_of_month def test_1(self): - wiz = self.wiz_obj.create({'batch_processing': False, - 'date_end': self.nextmonth}) + 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') + 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.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) + 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) + 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_2(self): - wiz = self.wiz_obj.create({'batch_processing': True, - 'date_end': self.nextmonth}) + 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') + 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.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) + 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) + 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) + 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.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) + 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 %s to %s" % ( - self.asset01.id, self.nextmonth) - jobs = self.env['queue.job'].search( - [('name', '=', job_name)], order='date_created desc', limit=1) + 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) 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) + depreciation_line = self.asset01.depreciation_line_ids.filtered( + lambda r: r.type == "depreciate" and r.move_id + ) self.assertEquals(len(depreciation_line), 1) diff --git a/account_asset_batch_compute/wizards/account_asset_compute.py b/account_asset_batch_compute/wizards/account_asset_compute.py index bae67dee7..86d163a94 100644 --- a/account_asset_batch_compute/wizards/account_asset_compute.py +++ b/account_asset_batch_compute/wizards/account_asset_compute.py @@ -1,38 +1,39 @@ # Copyright 2016-2017 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models, _ - import logging + +from odoo import _, api, fields, models + _logger = logging.getLogger(__name__) try: from odoo.addons.queue_job.job import job except ImportError: - _logger.debug('Can not `import queue_job`.') + _logger.debug("Can not `import queue_job`.") class AccountAssetCompute(models.TransientModel): - _inherit = 'account.asset.compute' + _inherit = "account.asset.compute" batch_processing = fields.Boolean() @api.multi - @job(default_channel='root.account_asset_batch_compute') + @job(default_channel="root.account_asset_batch_compute") def asset_compute(self): self.ensure_one() if not self.batch_processing: return super(AccountAssetCompute, self).asset_compute() - if not self.env.context.get('job_uuid') and not self.env.context.get( - 'test_queue_job_no_delay' + 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,) + description = _("Creating jobs to create moves for assets to %s") % ( + self.date_end, + ) job = self.with_delay(description=description).asset_compute() - return u'Job created with uuid %s' % (job.uuid,) + return u"Job created with uuid {}".format(job.uuid) else: return super( - AccountAssetCompute, self.with_context( - asset_batch_processing=True)).asset_compute() + 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 index e06181e1a..8c882b3cd 100644 --- a/account_asset_batch_compute/wizards/account_asset_compute_views.xml +++ b/account_asset_batch_compute/wizards/account_asset_compute_views.xml @@ -1,18 +1,20 @@ - + - - - account.asset.compute (in account_asset_batch_compute) + account.asset.compute (in account_asset_batch_compute) account.asset.compute - + - From d7668ead8f82fe71640df19618ca28dfb63a1fa7 Mon Sep 17 00:00:00 2001 From: Alba Riera Date: Mon, 22 Feb 2021 18:39:52 +0100 Subject: [PATCH 08/13] [MIG] account_asset_batch_compute: Migration to 13.0 --- account_asset_batch_compute/README.rst | 16 ++++++------- account_asset_batch_compute/__manifest__.py | 8 +++---- .../data/queue_data.xml | 23 +++++++++++++++++++ .../i18n/account_asset_batch_compute.pot | 11 ++++----- .../models/account_asset.py | 13 +---------- .../readme/CONTRIBUTORS.rst | 3 ++- .../static/description/index.html | 11 +++++---- .../tests/test_account_asset_batch_compute.py | 23 +++++++++++++++---- .../wizards/account_asset_compute.py | 13 +---------- 9 files changed, 68 insertions(+), 53 deletions(-) create mode 100644 account_asset_batch_compute/data/queue_data.xml diff --git a/account_asset_batch_compute/README.rst b/account_asset_batch_compute/README.rst index fa64141be..0fa7bc52c 100644 --- a/account_asset_batch_compute/README.rst +++ b/account_asset_batch_compute/README.rst @@ -14,13 +14,13 @@ Account Asset Batch Compute :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/12.0/account_asset_batch_compute + :target: https://github.com/OCA/account-financial-tools/tree/13.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-12-0/account-financial-tools-12-0-account_asset_batch_compute + :target: https://translation.odoo-community.org/projects/account-financial-tools-13-0/account-financial-tools-13-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/12.0 + :target: https://runbot.odoo-community.org/runbot/92/13.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -29,7 +29,6 @@ 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:: @@ -41,7 +40,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -52,13 +51,14 @@ Authors ~~~~~~~ * ACSONE SA/NV -* Eficent +* ForgeFlow Contributors ~~~~~~~~~~~~ * Adrien Peiffer -* Jordi Ballester Alomar +* Jordi Ballester Alomar +* Alba Riera Maintainers ~~~~~~~~~~~ @@ -73,6 +73,6 @@ 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. +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/__manifest__.py b/account_asset_batch_compute/__manifest__.py index 1b941025e..6138dad20 100644 --- a/account_asset_batch_compute/__manifest__.py +++ b/account_asset_batch_compute/__manifest__.py @@ -5,10 +5,10 @@ "name": "Account Asset Batch Compute", "summary": """ Add the possibility to compute assets in batch""", - "version": "12.0.1.0.0", + "version": "13.0.1.0.0", "license": "AGPL-3", - "author": "ACSONE SA/NV," "Eficent," "Odoo Community Association (OCA)", + "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",], + "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 000000000..ebb5ca8cc --- /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 index b146524b1..54bad2d25 100644 --- a/account_asset_batch_compute/i18n/account_asset_batch_compute.pot +++ b/account_asset_batch_compute/i18n/account_asset_batch_compute.pot @@ -1,12 +1,12 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * account_asset_batch_compute +# * account_asset_batch_compute # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"Last-Translator: <>\n" +"Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -29,14 +29,13 @@ msgid "Compute Assets" msgstr "" #. module: account_asset_batch_compute -#: code:addons/account_asset_batch_compute/wizards/account_asset_compute.py:31 +#: code:addons/account_asset_batch_compute/wizards/account_asset_compute.py:0 #, python-format msgid "Creating jobs to create moves for assets to %s" msgstr "" #. module: account_asset_batch_compute -#: code:addons/account_asset_batch_compute/models/account_asset.py:29 +#: code:addons/account_asset_batch_compute/models/account_asset.py:0 #, python-format msgid "Creating move for asset with id %s to %s" msgstr "" - diff --git a/account_asset_batch_compute/models/account_asset.py b/account_asset_batch_compute/models/account_asset.py index 4112dcba1..761c7f585 100644 --- a/account_asset_batch_compute/models/account_asset.py +++ b/account_asset_batch_compute/models/account_asset.py @@ -1,24 +1,13 @@ # Copyright 2016 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -import logging - -from odoo import _, api, models - -_logger = logging.getLogger(__name__) - -try: - from odoo.addons.queue_job.job import job -except ImportError: - _logger.debug("Can not `import queue_job`.") +from odoo import _, models class AccountAsset(models.Model): _inherit = "account.asset" - @api.multi - @job(default_channel="root.account_asset_batch_compute") def _compute_entries(self, date_end, check_triggers=False): if self.env.context.get( "asset_batch_processing", False diff --git a/account_asset_batch_compute/readme/CONTRIBUTORS.rst b/account_asset_batch_compute/readme/CONTRIBUTORS.rst index 615367e6f..13321599b 100644 --- a/account_asset_batch_compute/readme/CONTRIBUTORS.rst +++ b/account_asset_batch_compute/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Adrien Peiffer -* Jordi Ballester Alomar +* Jordi Ballester Alomar +* Alba Riera diff --git a/account_asset_batch_compute/static/description/index.html b/account_asset_batch_compute/static/description/index.html index 716ae194e..d7e963b4c 100644 --- a/account_asset_batch_compute/static/description/index.html +++ b/account_asset_batch_compute/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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.

@@ -388,7 +388,7 @@ this process in batch.

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.

+feedback.

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

@@ -397,14 +397,15 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

Authors

  • ACSONE SA/NV
  • -
  • Eficent
  • +
  • ForgeFlow

Contributors

@@ -414,7 +415,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

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.

+

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/test_account_asset_batch_compute.py b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py index 1ffaa573e..c5dee2477 100644 --- a/account_asset_batch_compute/tests/test_account_asset_batch_compute.py +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -1,5 +1,5 @@ # Copyright 2016-19 ACSONE SA/NV -# Copyright 2019 Eficent Business and IT Consulting Services, S.L. +# Copyright 2019 ForgeFlow S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import time from datetime import date @@ -19,7 +19,7 @@ class TestAccountAssetBatchCompute(TransactionCase): self.asset_profile_model = self.env["account.asset.profile"] self.account_account_type_model = self.env["account.account.type"] self.account_type_regular = self.account_account_type_model.create( - {"name": "Test Regular", "type": "other",} + {"name": "Test Regular", "type": "other", "internal_group": "liability"} ) self.account = self.env["account.account"].create( { @@ -29,7 +29,7 @@ class TestAccountAssetBatchCompute(TransactionCase): } ) self.journal = self.env["account.journal"].create( - {"name": "Test Journal", "code": "TJ", "type": "general",} + {"name": "Test Journal", "code": "TJ", "type": "general"} ) self.profile = self.asset_profile_model.create( { @@ -65,7 +65,7 @@ class TestAccountAssetBatchCompute(TransactionCase): self.nextmonth = first_day_of_month + relativedelta.relativedelta(months=1) self.asset01.date_start = first_day_of_month - def test_1(self): + def test_no_batch_processing(self): wiz = self.wiz_obj.create( {"batch_processing": False, "date_end": self.nextmonth} ) @@ -87,7 +87,7 @@ class TestAccountAssetBatchCompute(TransactionCase): ) self.assertTrue(len(depreciation_line) == 1) - def test_2(self): + def test_batch_processing(self): wiz = self.wiz_obj.create( {"batch_processing": True, "date_end": self.nextmonth} ) @@ -112,6 +112,13 @@ class TestAccountAssetBatchCompute(TransactionCase): 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 @@ -127,6 +134,12 @@ class TestAccountAssetBatchCompute(TransactionCase): [("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( diff --git a/account_asset_batch_compute/wizards/account_asset_compute.py b/account_asset_batch_compute/wizards/account_asset_compute.py index 86d163a94..2e721f9cf 100644 --- a/account_asset_batch_compute/wizards/account_asset_compute.py +++ b/account_asset_batch_compute/wizards/account_asset_compute.py @@ -1,16 +1,7 @@ # Copyright 2016-2017 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -import logging - -from odoo import _, api, fields, models - -_logger = logging.getLogger(__name__) - -try: - from odoo.addons.queue_job.job import job -except ImportError: - _logger.debug("Can not `import queue_job`.") +from odoo import _, fields, models class AccountAssetCompute(models.TransientModel): @@ -19,8 +10,6 @@ class AccountAssetCompute(models.TransientModel): batch_processing = fields.Boolean() - @api.multi - @job(default_channel="root.account_asset_batch_compute") def asset_compute(self): self.ensure_one() if not self.batch_processing: From 2221ea7a760bb5a7a60274e047d1f9082bad29d0 Mon Sep 17 00:00:00 2001 From: Olga Marco Date: Wed, 12 Jan 2022 10:04:42 +0100 Subject: [PATCH 09/13] [IMP] account_asset_batch_compute: black, isort, prettier --- .../tests/test_account_asset_batch_compute.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index c5dee2477..1c86229b8 100644 --- a/account_asset_batch_compute/tests/test_account_asset_batch_compute.py +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -128,7 +128,8 @@ class TestAccountAssetBatchCompute(TransactionCase): ) self.assertTrue(len(depreciation_line) == 0) job_name = "Creating move for asset with id {} to {}".format( - self.asset01.id, self.nextmonth, + self.asset01.id, + self.nextmonth, ) jobs = self.env["queue.job"].search( [("name", "=", job_name)], order="date_created desc", limit=1 From 0e579655178ae43ab2c763701e70d69509356122 Mon Sep 17 00:00:00 2001 From: Olga Marco Date: Wed, 12 Jan 2022 10:05:38 +0100 Subject: [PATCH 10/13] [MIG] account_asset_batch_compute: Migration to 14.0 [UPD] Update account_asset_batch_compute.pot [UPD] README.rst --- account_asset_batch_compute/README.rst | 10 +++++----- account_asset_batch_compute/__manifest__.py | 2 +- .../i18n/account_asset_batch_compute.pot | 20 ++++++++++++++++++- .../static/description/index.html | 6 +++--- .../tests/test_account_asset_batch_compute.py | 7 ------- .../wizards/account_asset_compute.py | 2 +- 6 files changed, 29 insertions(+), 18 deletions(-) diff --git a/account_asset_batch_compute/README.rst b/account_asset_batch_compute/README.rst index 0fa7bc52c..f683553c8 100644 --- a/account_asset_batch_compute/README.rst +++ b/account_asset_batch_compute/README.rst @@ -14,13 +14,13 @@ Account Asset Batch Compute :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/13.0/account_asset_batch_compute + :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-13-0/account-financial-tools-13-0-account_asset_batch_compute + :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/13.0 + :target: https://runbot.odoo-community.org/runbot/92/14.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -40,7 +40,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -73,6 +73,6 @@ 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. +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/__manifest__.py b/account_asset_batch_compute/__manifest__.py index 6138dad20..e454ecce3 100644 --- a/account_asset_batch_compute/__manifest__.py +++ b/account_asset_batch_compute/__manifest__.py @@ -5,7 +5,7 @@ "name": "Account Asset Batch Compute", "summary": """ Add the possibility to compute assets in batch""", - "version": "13.0.1.0.0", + "version": "14.0.1.0.0", "license": "AGPL-3", "author": "ACSONE SA/NV,ForgeFlow,Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", diff --git a/account_asset_batch_compute/i18n/account_asset_batch_compute.pot b/account_asset_batch_compute/i18n/account_asset_batch_compute.pot index 54bad2d25..4a5b673d6 100644 --- a/account_asset_batch_compute/i18n/account_asset_batch_compute.pot +++ b/account_asset_batch_compute/i18n/account_asset_batch_compute.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 13.0\n" +"Project-Id-Version: Odoo Server 14.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: \n" "Language-Team: \n" @@ -39,3 +39,21 @@ msgstr "" #, python-format msgid "Creating move for asset with id %s to %s" 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/static/description/index.html b/account_asset_batch_compute/static/description/index.html index d7e963b4c..15c03ea01 100644 --- a/account_asset_batch_compute/static/description/index.html +++ b/account_asset_batch_compute/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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.

@@ -388,7 +388,7 @@ this process in batch.

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.

+feedback.

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

@@ -415,7 +415,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

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.

+

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/test_account_asset_batch_compute.py b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py index 1c86229b8..ef4784dc3 100644 --- a/account_asset_batch_compute/tests/test_account_asset_batch_compute.py +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -40,13 +40,6 @@ class TestAccountAssetBatchCompute(TransactionCase): "name": "Test", } ) - self.fiscal_year = self.env["account.fiscal.year"].create( - { - "name": "FY", - "date_from": time.strftime("2019-01-01"), - "date_to": time.strftime("2019-12-31"), - } - ) self.asset01 = self.asset_model.create( { "name": "test asset", diff --git a/account_asset_batch_compute/wizards/account_asset_compute.py b/account_asset_batch_compute/wizards/account_asset_compute.py index 2e721f9cf..dfc2f4d6e 100644 --- a/account_asset_batch_compute/wizards/account_asset_compute.py +++ b/account_asset_batch_compute/wizards/account_asset_compute.py @@ -21,7 +21,7 @@ class AccountAssetCompute(models.TransientModel): self.date_end, ) job = self.with_delay(description=description).asset_compute() - return u"Job created with uuid {}".format(job.uuid) + return "Job created with uuid {}".format(job.uuid) else: return super( AccountAssetCompute, self.with_context(asset_batch_processing=True) From def3d56038081e3db40f3ad374416b47041c591f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Ra=C3=AFch?= Date: Fri, 6 May 2022 10:47:18 +0200 Subject: [PATCH 11/13] [FIX] account_asset_batch_compute: assertEquals -> assertEqual --- .../tests/test_account_asset_batch_compute.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index ef4784dc3..aae3b257f 100644 --- a/account_asset_batch_compute/tests/test_account_asset_batch_compute.py +++ b/account_asset_batch_compute/tests/test_account_asset_batch_compute.py @@ -139,4 +139,4 @@ class TestAccountAssetBatchCompute(TransactionCase): depreciation_line = self.asset01.depreciation_line_ids.filtered( lambda r: r.type == "depreciate" and r.move_id ) - self.assertEquals(len(depreciation_line), 1) + self.assertEqual(len(depreciation_line), 1) From fd180d97485497cb27235dda6c9527c6d46eb141 Mon Sep 17 00:00:00 2001 From: Olga Marco Date: Thu, 19 May 2022 11:28:34 +0200 Subject: [PATCH 12/13] [IMP] account_asset_batch_compute: black, isort, prettier --- .../odoo/addons/account_asset_batch_compute | 1 + setup/account_asset_batch_compute/setup.py | 6 ++++++ 2 files changed, 7 insertions(+) create mode 120000 setup/account_asset_batch_compute/odoo/addons/account_asset_batch_compute create mode 100644 setup/account_asset_batch_compute/setup.py 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 000000000..6ff71b28a --- /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 000000000..28c57bb64 --- /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, +) From df55f07d1b267d000ab0b19124cbbc28e875efdb Mon Sep 17 00:00:00 2001 From: Olga Marco Date: Thu, 19 May 2022 11:28:57 +0200 Subject: [PATCH 13/13] [MIG] account_asset_batch_compute: Migration to 15.0 --- account_asset_batch_compute/__manifest__.py | 2 +- account_asset_batch_compute/models/account_asset.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/account_asset_batch_compute/__manifest__.py b/account_asset_batch_compute/__manifest__.py index e454ecce3..5033be09a 100644 --- a/account_asset_batch_compute/__manifest__.py +++ b/account_asset_batch_compute/__manifest__.py @@ -5,7 +5,7 @@ "name": "Account Asset Batch Compute", "summary": """ Add the possibility to compute assets in batch""", - "version": "14.0.1.0.0", + "version": "15.0.1.0.0", "license": "AGPL-3", "author": "ACSONE SA/NV,ForgeFlow,Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", diff --git a/account_asset_batch_compute/models/account_asset.py b/account_asset_batch_compute/models/account_asset.py index 761c7f585..ff05064eb 100644 --- a/account_asset_batch_compute/models/account_asset.py +++ b/account_asset_batch_compute/models/account_asset.py @@ -15,10 +15,12 @@ class AccountAsset(models.Model): results = [] log_error = "" for record in self: - description = _("Creating move for asset with id %s to %s") % ( - record.id, - date_end, - ) + description = _( + "Creating move for asset with id %(id)s to %(date_end)s" + ) % { + "id": record.id, + "date_end": date_end, + } record.with_delay(description=description)._compute_entries( date_end, check_triggers=check_triggers )