migrate account_asset_batch_compute
This commit is contained in:
parent
2db6a14053
commit
d94fdeff34
@ -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
|
||||
<https://github.com/OCA/account-financial-tools/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 <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Adrien Peiffer <adrien.peiffer@acsone.eu>
|
||||
|
||||
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.
|
@ -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',
|
||||
],
|
||||
}
|
||||
|
@ -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)
|
||||
|
2
account_asset_batch_compute/readme/CONTRIBUTORS.rst
Normal file
2
account_asset_batch_compute/readme/CONTRIBUTORS.rst
Normal file
@ -0,0 +1,2 @@
|
||||
* Adrien Peiffer
|
||||
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
|
4
account_asset_batch_compute/readme/DESCRIPTION.rst
Normal file
4
account_asset_batch_compute/readme/DESCRIPTION.rst
Normal file
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -1 +1 @@
|
||||
from . import asset_depreciation_confirmation_wizard
|
||||
from . import account_asset_compute
|
||||
|
@ -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()
|
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2016 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record model="ir.ui.view" id="account_asset_compute_view_form">
|
||||
<field name="name">account.asset.compute (in account_asset_batch_compute)</field>
|
||||
<field name="model">account.asset.compute</field>
|
||||
<field name="inherit_id" ref="account_asset_management.account_asset_compute_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="date_end" position="after">
|
||||
<field name="batch_processing" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2016 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record model="ir.ui.view" id="asset_depreciation_confirmation_wizard_form_view">
|
||||
<field name="name">asset.depreciation.confirmation.wizard.form (in account_asset_batch_compute)</field>
|
||||
<field name="model">asset.depreciation.confirmation.wizard</field>
|
||||
<field name="inherit_id" ref="account_asset_management.view_asset_depreciation_confirmation_wizard"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="date_end" position="after">
|
||||
<field name="batch_processing" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue
Block a user