Files
Odoo-Modules/fusion_accounting_assets/tests/test_partial_sale_wizard.py
2026-04-19 20:05:17 -04:00

49 lines
1.7 KiB
Python

from datetime import date
from odoo.exceptions import UserError
from odoo.tests import tagged
from odoo.tests.common import TransactionCase
@tagged('post_install', '-at_install')
class TestPartialSaleWizard(TransactionCase):
def setUp(self):
super().setUp()
self.asset = self.env['fusion.asset'].create({
'name': 'Partial Sale Test',
'cost': 10000,
'acquisition_date': date(2026, 1, 1),
'in_service_date': date(2026, 1, 1),
'method': 'straight_line', 'useful_life_years': 5,
})
self.env['fusion.asset.engine'].compute_depreciation_schedule(self.asset)
self.asset.action_set_running()
def test_partial_sell_30pct_creates_child(self):
wizard = self.env['fusion.partial.sale.wizard'].create({
'asset_id': self.asset.id,
'sold_pct': 30.0, 'sold_amount': 4000,
'sale_date': date(2026, 6, 1),
})
wizard.action_partial_sell()
self.asset.invalidate_recordset(['cost'])
self.assertAlmostEqual(self.asset.cost, 7000, places=2)
def test_invalid_pct_raises(self):
wizard = self.env['fusion.partial.sale.wizard'].create({
'asset_id': self.asset.id,
'sold_pct': 0, 'sold_amount': 100,
})
with self.assertRaises(UserError):
wizard.action_partial_sell()
def test_compute_estimated_gain_loss(self):
wizard = self.env['fusion.partial.sale.wizard'].new({
'asset_id': self.asset.id,
'sold_pct': 30.0, 'sold_amount': 4000,
})
wizard._compute_sold_cost()
self.assertAlmostEqual(wizard.estimated_sold_cost, 3000, places=2)
self.assertAlmostEqual(wizard.estimated_gain_loss, 1000, places=2)