如何显示计算出的one2many字段Odoo(api v8)
我想知道如何在树视图中显示one2many计算字段,我尝试了以下代码,但没有结果:如何显示计算出的one2many字段Odoo(api v8),odoo,Odoo,我想知道如何在树视图中显示one2many计算字段,我尝试了以下代码,但没有结果: @api.one def _compute_o2m_field(self): related_recordset = self.env["product.product"].search([]) self.productos = related_recordset products = fields.One2many(string="products", compute='_compute_o2
@api.one
def _compute_o2m_field(self):
related_recordset = self.env["product.product"].search([])
self.productos = related_recordset
products = fields.One2many(string="products", compute='_compute_o2m_field')
有什么想法吗?,
谢谢计算字段
不再直接创建fields.function。
而是添加一个compute-kwarg。值是作为字符串或函数的函数名。这允许
在类的顶部有字段定义
你的计算函数应该是这样的
@api.multi
def _compute_o2m_field(self):
related_recordset = self.env["product.product"].search([])
for obj in self:
obj.products = related_recordset
products = fields.One2many(comodel_name,comodel_name,string="products", compute='_compute_o2m_field')
One2many
存储多行co模型的关系
具体选择:
• comodel_name: name of the opposite model
• comodel_name: relational column of the opposite model
你的字段定义应该是这样的
@api.multi
def _compute_o2m_field(self):
related_recordset = self.env["product.product"].search([])
for obj in self:
obj.products = related_recordset
products = fields.One2many(comodel_name,comodel_name,string="products", compute='_compute_o2m_field')
好的,使用related_recordset.ids我有一个产品的ids列表,现在,我想用产品数据进行一些计算,并将它们显示在自定义表中,如何在树状视图中显示此表,我尝试了:,但它只显示标签,而不显示字段的值,也许我可以用Qweb模板完成此操作???,谢谢回答