test(fusion_accounting_assets): integration tests for all 3 depreciation methods

Made-with: Cursor
This commit is contained in:
gsinghpal
2026-04-19 17:23:41 -04:00
parent 1e70b8d5c0
commit c939b83812
2 changed files with 113 additions and 0 deletions

View File

@@ -16,3 +16,4 @@ from . import test_assets_adapter
from . import test_asset_tools
from . import test_assets_cron
from . import test_engine_property
from . import test_method_integration

View File

@@ -0,0 +1,112 @@
"""Integration tests verifying all 3 depreciation methods through the engine."""
from datetime import date
from odoo.tests.common import TransactionCase
from odoo.tests import tagged
@tagged('post_install', '-at_install', 'integration')
class TestStraightLineIntegration(TransactionCase):
def setUp(self):
super().setUp()
self.engine = self.env['fusion.asset.engine']
def test_straight_line_5yr_no_salvage(self):
asset = self.env['fusion.asset'].create({
'name': 'SL Test', 'cost': 10000, 'salvage_value': 0,
'acquisition_date': date(2026, 1, 1),
'in_service_date': date(2026, 1, 1),
'method': 'straight_line', 'useful_life_years': 5,
})
self.engine.compute_depreciation_schedule(asset)
lines = asset.depreciation_line_ids.sorted('period_index')
self.assertEqual(len(lines), 5)
for line in lines:
self.assertAlmostEqual(line.amount, 2000, places=2)
def test_straight_line_10yr_with_salvage(self):
asset = self.env['fusion.asset'].create({
'name': 'SL10', 'cost': 50000, 'salvage_value': 5000,
'acquisition_date': date(2026, 1, 1),
'in_service_date': date(2026, 1, 1),
'method': 'straight_line', 'useful_life_years': 10,
})
self.engine.compute_depreciation_schedule(asset)
lines = asset.depreciation_line_ids.sorted('period_index')
self.assertEqual(len(lines), 10)
# Each year = (50000-5000)/10 = 4500; total depreciable = 45000
self.assertAlmostEqual(sum(lines.mapped('amount')), 45000, places=2)
def test_straight_line_book_value_at_end_equals_salvage(self):
asset = self.env['fusion.asset'].create({
'name': 'SL', 'cost': 10000, 'salvage_value': 1000,
'acquisition_date': date(2026, 1, 1),
'in_service_date': date(2026, 1, 1),
'method': 'straight_line', 'useful_life_years': 5,
})
self.engine.compute_depreciation_schedule(asset)
last = asset.depreciation_line_ids.sorted('period_index')[-1]
self.assertAlmostEqual(last.book_value_at_end, 1000, places=2)
@tagged('post_install', '-at_install', 'integration')
class TestDecliningBalanceIntegration(TransactionCase):
def setUp(self):
super().setUp()
self.engine = self.env['fusion.asset.engine']
def test_declining_balance_30pct(self):
asset = self.env['fusion.asset'].create({
'name': 'DB', 'cost': 10000, 'salvage_value': 1000,
'acquisition_date': date(2026, 1, 1),
'in_service_date': date(2026, 1, 1),
'method': 'declining_balance', 'useful_life_years': 5,
'declining_rate_pct': 30.0,
})
self.engine.compute_depreciation_schedule(asset)
lines = asset.depreciation_line_ids.sorted('period_index')
# First period: 10000 * 0.30 = 3000
self.assertAlmostEqual(lines[0].amount, 3000, places=2)
# Should not exceed salvage at end
self.assertGreaterEqual(lines[-1].book_value_at_end, 999.99)
def test_declining_balance_50pct_high_rate(self):
asset = self.env['fusion.asset'].create({
'name': 'DB50', 'cost': 8000, 'salvage_value': 500,
'acquisition_date': date(2026, 1, 1),
'in_service_date': date(2026, 1, 1),
'method': 'declining_balance', 'useful_life_years': 5,
'declining_rate_pct': 50.0,
})
self.engine.compute_depreciation_schedule(asset)
# First period: 8000 * 0.50 = 4000
first = asset.depreciation_line_ids.sorted('period_index')[0]
self.assertAlmostEqual(first.amount, 4000, places=2)
@tagged('post_install', '-at_install', 'integration')
class TestUnitsOfProductionIntegration(TransactionCase):
def setUp(self):
super().setUp()
self.engine = self.env['fusion.asset.engine']
def test_units_of_production_5yr_even_distribution(self):
asset = self.env['fusion.asset'].create({
'name': 'UOP', 'cost': 50000, 'salvage_value': 0,
'acquisition_date': date(2026, 1, 1),
'in_service_date': date(2026, 1, 1),
'method': 'units_of_production',
'total_units_expected': 100000,
'useful_life_years': 5,
})
self.engine.compute_depreciation_schedule(asset)
lines = asset.depreciation_line_ids.sorted('period_index')
# 5 periods, even distribution = 20000 units/period
# Each period: (20000/100000) * 50000 = 10000
self.assertEqual(len(lines), 5)
for line in lines:
self.assertAlmostEqual(line.amount, 10000, places=2)