Skip to content

Commit

Permalink
[FIX] test script
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Feb 20, 2023
1 parent e7c0a0e commit 41844a0
Showing 1 changed file with 8 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,78 +1,19 @@
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import time

from freezegun import freeze_time

from odoo.tests import tagged
from odoo.tests.common import Form

from odoo.addons.account_asset_management.tests.test_account_asset_management import (
TestAssetManagement,
from odoo.addons.account_asset_compute_batch.tests.test_account_asset_compute_batch import (
TestAssetComputeBatch,
)


@tagged("post_install", "-at_install")
class TestAssetComputeBatch(TestAssetManagement):
class TestAssetComputeBatchJob(TestAssetComputeBatch):
@classmethod
@freeze_time("2000-01-01")
def setUpClass(cls):
super().setUpClass()
# Create 3 assets from 2 profiles
cls.ict0 = cls.asset_model.create(
{
"state": "draft",
"method_time": "year",
"method_number": 3,
"method_period": "year",
"name": "Laptop",
"code": "PI00101",
"purchase_value": 1500.0,
"profile_id": cls.ict3Y.id,
"date_start": time.strftime("2000-01-01"),
}
)
cls.ict1 = cls.asset_model.create(
{
"state": "draft",
"method_time": "year",
"method_number": 3,
"method_period": "year",
"name": "Monitor",
"code": "PI00102",
"purchase_value": 2100.0,
"profile_id": cls.ict3Y.id,
"date_start": time.strftime("2000-01-01"),
}
)
# 2nd asset
cls.vehicle0 = cls.asset_model.create(
{
"state": "draft",
"method_time": "year",
"method_number": 5,
"method_period": "year",
"name": "CEO's Car",
"purchase_value": 12000.0,
"salvage_value": 2000.0,
"profile_id": cls.car5y.id,
"date_start": time.strftime("2000-01-01"),
}
)

def _create_compute_wizard(self, use_batch=False, delay_compute=False):
with Form(self.env["account.asset.compute"]) as f:
f.batch_name = "Test Batch"
f.description = "Compute asset with 2 profiles"
f.profile_ids.add(self.ict3Y)
f.profile_ids.add(self.car5y)
f.use_batch = use_batch
f.delay_compute = delay_compute
wiz = f.save()
return wiz

@freeze_time("2000-12-31")
def test_01_asset_compute_batch_job(self):
# Confirm 2 assets
self.ict0.validate()
Expand All @@ -83,11 +24,12 @@ def test_01_asset_compute_batch_job(self):
wiz = self._create_compute_wizard(use_batch=True, delay_compute=True)
res = wiz.asset_compute()
batch = self.env["account.asset.compute.batch"].browse(res["res_id"])
self.assertFalse(batch.run_job)
self.assertEqual(batch.state, "draft")
self.assertEqual(batch.depre_amount, 0)
# Batch will be posted by cron job
self.assertFalse(batch.job_state)
batch.with_context(compute_batch_job=1).action_compute_job()
self.assertFalse(batch.run_job)
self.assertEqual(batch.state, "computed")
self.assertEqual(batch.depre_amount, 2500)
self.assertEqual(batch.job_state, "pending")
# Check queue job should be 1
action = batch.open_queue_job()
self.assertEqual(action["domain"][0][2], batch.job_current.ids)

0 comments on commit 41844a0

Please sign in to comment.