- 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
35 lines
1003 B
Python
35 lines
1003 B
Python
"""Inherit account.move.line to link to fusion.asset records.
|
|
|
|
Lets us trace assets back to their source invoice line.
|
|
"""
|
|
|
|
from odoo import fields, models
|
|
|
|
|
|
class AccountMoveLine(models.Model):
|
|
_inherit = "account.move.line"
|
|
|
|
fusion_asset_id = fields.Many2one(
|
|
'fusion.asset', string='Created Asset',
|
|
copy=False, ondelete='set null',
|
|
help="Fusion asset record created from this invoice line.",
|
|
)
|
|
|
|
fusion_asset_count = fields.Integer(compute='_compute_fusion_asset_count')
|
|
|
|
def _compute_fusion_asset_count(self):
|
|
for line in self:
|
|
line.fusion_asset_count = 1 if line.fusion_asset_id else 0
|
|
|
|
def action_open_fusion_asset(self):
|
|
self.ensure_one()
|
|
if not self.fusion_asset_id:
|
|
return
|
|
return {
|
|
'type': 'ir.actions.act_window',
|
|
'res_model': 'fusion.asset',
|
|
'res_id': self.fusion_asset_id.id,
|
|
'view_mode': 'form',
|
|
'target': 'current',
|
|
}
|