Hi Gets,
Here, I need to show the count of Assets which is the same sparepartslinitem added.
Please help to get count of Many2one field in "set_countofasset"
using v12 community.
from odoo import models, fields, api
class Asset(models.Model):
_name = 'asset'
name = fields.Char(string="Code", required=True)
assetname = fields.Char(string='Asset Name')
sparepartslines = fields.One2many('spareparts_lineitem', 'asset', string='Spareparts')
qtyinasset = fields.Float(String="Qty in Asset", compute='set_qtyinasset', readonly=True)
# qtyinsystem = fields.Float(String="Qty in System", compute='set_qtyinsystem', readonly=True)
@api.depends('sparepartslines.quantity')
def set_qtyinasset(self):
for rec in self:
total = 0.0
for line in self.sparepartslines:
total += line.quantity
rec.update({'qtyinasset': total})
class Spareparts(models.Model):
_name = 'spareparts'
name = fields.Char(string="Item number", required=True)
description = fields.Char(string='Description')
class Spareparts_lineitem(models.Model):
_name = 'spareparts_lineitem'
name = fields.Many2one('spareparts', string="Item number", required=True)
description = fields.Char(string='Description', related='name.description', store=True, readonly=True)
quantity = fields.Float(string='Quantity', required=True)
quantityinstore= fields.Float(string='Qty in Store')
asset = fields.Many2one('asset', string="Asset")
countofasset = fields.Float(string='Qty in Store', compute='set_countofasset', readonly=True)