- fusion_asset_id Many2one on account.move.line (ondelete='set null': invoice line preserved if asset is removed) - fusion_asset_count compute (smart-button friendly) - action_open_fusion_asset() returns a window action to jump to the asset - 3 new tests (66 total) Made-with: Cursor
48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
from datetime import date
|
|
|
|
from odoo.tests.common import TransactionCase
|
|
from odoo.tests import tagged
|
|
|
|
|
|
@tagged('post_install', '-at_install')
|
|
class TestAccountMoveLineFusionAsset(TransactionCase):
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.asset = self.env['fusion.asset'].create({
|
|
'name': 'Asset From Invoice',
|
|
'cost': 8000,
|
|
'acquisition_date': date(2026, 1, 1),
|
|
})
|
|
self.partner = self.env['res.partner'].create({'name': 'Vendor X'})
|
|
product = self.env['product.product'].create({'name': 'Test Asset Item'})
|
|
bill = self.env['account.move'].create({
|
|
'move_type': 'in_invoice',
|
|
'partner_id': self.partner.id,
|
|
'invoice_date': date(2026, 1, 1),
|
|
'invoice_line_ids': [(0, 0, {
|
|
'product_id': product.id,
|
|
'name': 'Test asset purchase',
|
|
'quantity': 1,
|
|
'price_unit': 8000,
|
|
})],
|
|
})
|
|
self.invoice_line = bill.invoice_line_ids[0]
|
|
|
|
def test_line_starts_without_asset_link(self):
|
|
self.assertFalse(self.invoice_line.fusion_asset_id)
|
|
self.assertEqual(self.invoice_line.fusion_asset_count, 0)
|
|
|
|
def test_link_invoice_line_to_asset(self):
|
|
self.invoice_line.fusion_asset_id = self.asset
|
|
self.assertEqual(self.invoice_line.fusion_asset_id, self.asset)
|
|
self.invoice_line.invalidate_recordset(['fusion_asset_count'])
|
|
self.assertEqual(self.invoice_line.fusion_asset_count, 1)
|
|
|
|
def test_action_open_fusion_asset_returns_window_action(self):
|
|
self.invoice_line.fusion_asset_id = self.asset
|
|
action = self.invoice_line.action_open_fusion_asset()
|
|
self.assertEqual(action['res_model'], 'fusion.asset')
|
|
self.assertEqual(action['res_id'], self.asset.id)
|
|
self.assertEqual(action['view_mode'], 'form')
|