2019-10-31 07:20:20 +01:00
|
|
|
# Copyright 2016-19 ACSONE SA/NV
|
|
|
|
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
|
2016-08-25 15:26:49 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
2019-10-31 07:20:20 +01:00
|
|
|
import time
|
2017-03-23 07:52:07 +01:00
|
|
|
from odoo.tests.common import TransactionCase
|
2016-08-25 15:26:49 +02:00
|
|
|
from datetime import date
|
2017-03-23 07:52:07 +01:00
|
|
|
from dateutil import relativedelta
|
|
|
|
|
|
|
|
from odoo.addons.queue_job.job import Job
|
|
|
|
|
|
|
|
DELAY2 = ('odoo.addons.account_asset_batch_compute.wizards.'
|
2019-10-31 07:20:20 +01:00
|
|
|
'account_asset_compute.async_asset_compute')
|
2017-03-23 07:52:07 +01:00
|
|
|
DELAY1 = ('odoo.addons.account_asset_batch_compute.models.'
|
2019-10-31 07:20:20 +01:00
|
|
|
'account_asset.async_compute_entries')
|
2016-08-25 15:26:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestAccountAssetBatchCompute(TransactionCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestAccountAssetBatchCompute, self).setUp()
|
2019-10-31 07:20:20 +01:00
|
|
|
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,
|
|
|
|
})
|
2016-08-25 15:26:49 +02:00
|
|
|
today = date.today()
|
|
|
|
first_day_of_month = date(today.year, today.month, 1)
|
2017-03-23 07:52:07 +01:00
|
|
|
self.nextmonth =\
|
|
|
|
first_day_of_month + relativedelta.relativedelta(months=1)
|
|
|
|
self.nextmonth = first_day_of_month + relativedelta.relativedelta(
|
|
|
|
months=1)
|
2016-08-25 15:26:49 +02:00
|
|
|
self.asset01.date_start = first_day_of_month
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
wiz = self.wiz_obj.create({'batch_processing': False,
|
2017-03-23 07:52:07 +01:00
|
|
|
'date_end': self.nextmonth})
|
2016-08-25 15:26:49 +02:00
|
|
|
# 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):
|
|
|
|
wiz = self.wiz_obj.create({'batch_processing': True,
|
2017-03-23 07:52:07 +01:00
|
|
|
'date_end': self.nextmonth})
|
2016-08-25 15:26:49 +02:00
|
|
|
# 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)
|
2019-11-03 22:08:09 +01:00
|
|
|
wiz.with_context(test_queue_job_no_delay=False).asset_compute()
|
2017-03-23 07:52:07 +01:00
|
|
|
depreciation_line = self.asset01.depreciation_line_ids \
|
|
|
|
.filtered(lambda r: r.type == 'depreciate' and r.move_id)
|
|
|
|
self.assertTrue(len(depreciation_line) == 0)
|
2019-10-31 07:20:20 +01:00
|
|
|
job_name = "Creating jobs to create moves for assets to %s" % (
|
|
|
|
self.nextmonth)
|
2017-03-23 07:52:07 +01:00
|
|
|
jobs = self.env['queue.job'].search(
|
2019-10-31 07:20:20 +01:00
|
|
|
[('name', '=', job_name)], order='date_created desc', limit=1)
|
2017-03-23 07:52:07 +01:00
|
|
|
self.assertTrue(len(jobs) == 1)
|
|
|
|
job = Job.load(self.env, jobs.uuid)
|
2019-10-31 07:20:20 +01:00
|
|
|
# perform job
|
2017-03-23 07:52:07 +01:00
|
|
|
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)
|
2019-10-31 07:20:20 +01:00
|
|
|
job_name = "Creating move for asset with id %s to %s" % (
|
|
|
|
self.asset01.id, self.nextmonth)
|
2017-03-23 07:52:07 +01:00
|
|
|
jobs = self.env['queue.job'].search(
|
2019-10-31 07:20:20 +01:00
|
|
|
[('name', '=', job_name)], order='date_created desc', limit=1)
|
2017-03-23 07:52:07 +01:00
|
|
|
self.assertTrue(len(jobs) == 1)
|
|
|
|
job = Job.load(self.env, jobs.uuid)
|
|
|
|
job.perform()
|
|
|
|
depreciation_line = self.asset01.depreciation_line_ids \
|
2016-08-25 15:26:49 +02:00
|
|
|
.filtered(lambda r: r.type == 'depreciate' and r.move_id)
|
2019-10-31 07:20:20 +01:00
|
|
|
self.assertEquals(len(depreciation_line), 1)
|