[MIG] Migration of account_asset_batch_compute
This commit is contained in:
parent
b5db09dc88
commit
2db6a14053
@ -9,16 +9,12 @@ Account Asset Batch Compute
|
|||||||
Add the possibility to compute assets in batch.
|
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.
|
This module adds a flag on compute assets wizard in order to execute this process in batch.
|
||||||
|
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
|
||||||
|
|
||||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
:alt: Try me on Runbot
|
: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
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- 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).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Account Asset Batch Compute',
|
'name': 'Account Asset Batch Compute',
|
||||||
'summary': """
|
'summary': """
|
||||||
Add the possibility to compute assets in batch""",
|
Add the possibility to compute assets in batch""",
|
||||||
'version': '8.0.1.0.0',
|
'version': '10.0.1.0.0',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
|
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
|
||||||
'website': 'www.acsone.eu',
|
'website': 'www.acsone.eu',
|
||||||
'depends': [
|
'depends': [
|
||||||
'account_asset_management',
|
'account_asset_management',
|
||||||
'connector',
|
'queue_job',
|
||||||
],
|
],
|
||||||
'data': [
|
'data': [
|
||||||
'wizards/asset_depreciation_confirmation_wizard.xml',
|
'wizards/asset_depreciation_confirmation_wizard.xml',
|
@ -1 +1 @@
|
|||||||
from . import account_asset_asset
|
from . import account_asset
|
37
account_asset_batch_compute/models/account_asset.py
Normal file
37
account_asset_batch_compute/models/account_asset.py
Normal file
@ -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)
|
@ -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)
|
|
@ -2,32 +2,50 @@
|
|||||||
# Copyright 2016 ACSONE SA/NV
|
# Copyright 2016 ACSONE SA/NV
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from openerp.tests.common import TransactionCase
|
from odoo import tools
|
||||||
from openerp.addons.connector.tests.common import mock_job_delay_to_direct
|
from odoo.modules.module import get_resource_path
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase
|
||||||
from datetime import date
|
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')
|
'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')
|
'account_asset_asset.async_compute_entries')
|
||||||
|
|
||||||
|
|
||||||
class TestAccountAssetBatchCompute(TransactionCase):
|
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):
|
def setUp(self):
|
||||||
super(TestAccountAssetBatchCompute, self).setUp()
|
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.wiz_obj = self.env['asset.depreciation.confirmation.wizard']
|
||||||
self.asset01 = self.env.ref(
|
self.asset01 = self.env.ref(
|
||||||
'account_asset_management.account_asset_asset_ict0')
|
'account_asset_management.account_asset_ict0')
|
||||||
self.asset01.method_period = 'month'
|
self.asset01.method_period = 'month'
|
||||||
today = date.today()
|
today = date.today()
|
||||||
first_day_of_month = date(today.year, today.month, 1)
|
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
|
self.asset01.date_start = first_day_of_month
|
||||||
|
|
||||||
def test_1(self):
|
def test_1(self):
|
||||||
period = self.env['account.period'].find()
|
|
||||||
wiz = self.wiz_obj.create({'batch_processing': False,
|
wiz = self.wiz_obj.create({'batch_processing': False,
|
||||||
'period_id': period.id})
|
'date_end': self.nextmonth})
|
||||||
# I check if this asset is draft
|
# I check if this asset is draft
|
||||||
self.assertEqual(self.asset01.state, 'draft')
|
self.assertEqual(self.asset01.state, 'draft')
|
||||||
# I confirm this asset
|
# I confirm this asset
|
||||||
@ -45,9 +63,8 @@ class TestAccountAssetBatchCompute(TransactionCase):
|
|||||||
self.assertTrue(len(depreciation_line) == 1)
|
self.assertTrue(len(depreciation_line) == 1)
|
||||||
|
|
||||||
def test_2(self):
|
def test_2(self):
|
||||||
period = self.env['account.period'].find()
|
|
||||||
wiz = self.wiz_obj.create({'batch_processing': True,
|
wiz = self.wiz_obj.create({'batch_processing': True,
|
||||||
'period_id': period.id})
|
'date_end': self.nextmonth})
|
||||||
# I check if this asset is draft
|
# I check if this asset is draft
|
||||||
self.assertEqual(self.asset01.state, 'draft')
|
self.assertEqual(self.asset01.state, 'draft')
|
||||||
# I confirm this asset
|
# I confirm this asset
|
||||||
@ -59,9 +76,23 @@ class TestAccountAssetBatchCompute(TransactionCase):
|
|||||||
depreciation_line = self.asset01.depreciation_line_ids\
|
depreciation_line = self.asset01.depreciation_line_ids\
|
||||||
.filtered(lambda r: r.type == 'depreciate' and r.move_id)
|
.filtered(lambda r: r.type == 'depreciate' and r.move_id)
|
||||||
self.assertTrue(len(depreciation_line) == 0)
|
self.assertTrue(len(depreciation_line) == 0)
|
||||||
with mock_job_delay_to_direct(DELAY1),\
|
|
||||||
mock_job_delay_to_direct(DELAY2):
|
|
||||||
wiz.asset_compute()
|
wiz.asset_compute()
|
||||||
depreciation_line = self.asset01.depreciation_line_ids\
|
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)
|
.filtered(lambda r: r.type == 'depreciate' and r.move_id)
|
||||||
self.assertTrue(len(depreciation_line) == 1)
|
self.assertTrue(len(depreciation_line) == 1)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- 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).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from openerp import api, fields, models, _
|
from openerp import api, fields, models, _
|
||||||
@ -8,10 +8,9 @@ import logging
|
|||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from openerp.addons.connector.session import ConnectorSession
|
from odoo.addons.queue_job.job import job
|
||||||
from openerp.addons.connector.queue.job import job
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
_logger.debug('Can not `import connector`.')
|
_logger.debug('Can not `import queue_job`.')
|
||||||
|
|
||||||
def empty_decorator(func):
|
def empty_decorator(func):
|
||||||
return func
|
return func
|
||||||
@ -25,27 +24,19 @@ class AssetDepreciationConfirmationWizard(models.TransientModel):
|
|||||||
batch_processing = fields.Boolean()
|
batch_processing = fields.Boolean()
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
@job(default_channel='root.account_asset_batch_compute')
|
||||||
def asset_compute(self):
|
def asset_compute(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
if not self.batch_processing:
|
if not self.batch_processing:
|
||||||
return super(AssetDepreciationConfirmationWizard, self)\
|
return super(AssetDepreciationConfirmationWizard, self)\
|
||||||
.asset_compute()
|
.asset_compute()
|
||||||
if self.env.context.get('not_async'):
|
if not self.env.context.get('job_uuid'):
|
||||||
return super(AssetDepreciationConfirmationWizard,
|
description = \
|
||||||
self.with_context(asset_batch_processing=True))\
|
_("Creating jobs to create moves for assets to %s") % (
|
||||||
.asset_compute()
|
self.date_end,)
|
||||||
|
job = self.with_delay(description=description).asset_compute()
|
||||||
|
return u'Job created with uuid %s' % (job.uuid,)
|
||||||
else:
|
else:
|
||||||
session = ConnectorSession.from_env(self.env)
|
self = self.with_context(asset_batch_processing=True)
|
||||||
description =\
|
return super(AssetDepreciationConfirmationWizard, self)\
|
||||||
_("Creating jobs to create moves for assets period %s") % (
|
.asset_compute()
|
||||||
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()
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<field name="model">asset.depreciation.confirmation.wizard</field>
|
<field name="model">asset.depreciation.confirmation.wizard</field>
|
||||||
<field name="inherit_id" ref="account_asset_management.view_asset_depreciation_confirmation_wizard"/>
|
<field name="inherit_id" ref="account_asset_management.view_asset_depreciation_confirmation_wizard"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="period_id" position="after">
|
<field name="date_end" position="after">
|
||||||
<field name="batch_processing" />
|
<field name="batch_processing" />
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
|
Loading…
Reference in New Issue
Block a user