ga_asset_management/models/product_template.py
2026-02-04 11:37:09 +07:00

27 lines
1000 B
Python

from odoo import models, fields, api
class ProductTemplate(models.Model):
_inherit = 'product.template'
asset_count = fields.Integer(string='Assets', compute='_compute_asset_count')
def _compute_asset_count(self):
# account.asset has product_id which links to product.product
# We need to count assets for all variants of this template
for product in self:
# Domain: product_id.product_tmpl_id = product.id
product.asset_count = self.env['account.asset'].search_count([
('product_id.product_tmpl_id', '=', product.id)
])
def action_view_assets(self):
self.ensure_one()
return {
'name': 'Assets',
'type': 'ir.actions.act_window',
'res_model': 'account.asset',
'view_mode': 'tree,form',
'domain': [('product_id.product_tmpl_id', '=', self.id)],
'context': {'default_product_id': self.product_variant_id.id},
}