from datetime import date from odoo.tests import tagged from odoo.tests.common import TransactionCase @tagged('post_install', '-at_install') class TestCreateAssetWizard(TransactionCase): def setUp(self): super().setUp() self.env['ir.config_parameter'].sudo().search([ ('key', 'in', ['fusion_accounting.provider.asset_useful_life', 'fusion_accounting.provider.default']) ]).unlink() def test_create_minimal_asset(self): wizard = self.env['fusion.create.asset.wizard'].create({ 'name': 'Test Asset', 'cost': 5000, 'method': 'straight_line', 'useful_life_years': 5, 'acquisition_date': date(2026, 1, 1), 'source_invoice_line_id': False, }) action = wizard.action_create_asset() self.assertEqual(action['res_model'], 'fusion.asset') asset = self.env['fusion.asset'].browse(action['res_id']) self.assertEqual(asset.name, 'Test Asset') self.assertEqual(asset.cost, 5000) def test_ai_suggest_fills_fields(self): wizard = self.env['fusion.create.asset.wizard'].create({ 'name': 'Dell laptop', 'cost': 2000, 'method': 'straight_line', 'useful_life_years': 5, 'acquisition_date': date(2026, 1, 1), }) wizard.action_ai_suggest() self.assertEqual(wizard.ai_suggested_years, 4) self.assertEqual(wizard.useful_life_years, 4) def test_category_onchange_pre_fills(self): category = self.env['fusion.asset.category'].create({ 'name': 'Test Category', 'method': 'declining_balance', 'useful_life_years': 7, 'declining_rate_pct': 25.0, 'salvage_value_pct': 10.0, }) wizard = self.env['fusion.create.asset.wizard'].new({ 'name': 'Test', 'cost': 10000, 'method': 'straight_line', 'useful_life_years': 5, 'acquisition_date': date(2026, 1, 1), 'category_id': category.id, }) wizard._onchange_category_id() self.assertEqual(wizard.method, 'declining_balance') self.assertEqual(wizard.useful_life_years, 7) self.assertEqual(wizard.declining_rate_pct, 25.0) self.assertAlmostEqual(wizard.salvage_value, 1000, places=2)