diff --git a/account_asset_batch_compute/README.rst b/account_asset_batch_compute/README.rst
index cc575532..76198cb3 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 c3cd5d45..d6a4ccbb 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 4e8f0c98..8be8e8ae 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 00000000..743cebab
--- /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 b108b919..00000000
--- 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 1380f9f1..73e38636 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 1c7702ca..455319be 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 aaddde9d..a2c4f44e 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
-
+