Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4975 Lượt xem

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)
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Little confusion above the requirement is the count of Assets which is the same spareparts added in the sparepartslinitem screen?? In that case
@api.depends('name')
def set_countofasset(self):
    for line in self:
        line.countofasset = self.search_count([('asset', '=',line.asset.id),('name','=',line.name.id)]

or see the below link

https://www.odoo.com/forum/help-1/question/how-to-count-stockable-product-in-orderline-in-quotations-148069

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Thank you so much @Prakash for your respond.

when i applied your code, it is getting the count of sparepartslines only.

But Actually I required the count of assets which is the same sparepartsline added in whole asset record.

Kindly help..

Ảnh đại diện
Huỷ bỏ

updated answer

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 20
3933
3
thg 12 19
4799
1
thg 12 19
3854
1
thg 6 25
25047
2
thg 7 22
4211