我在 GUI Odoo 中创建一个字段,有一个带有“计算”的方法。但我无法得到它。
我在 sale.py 模块的 sale.order.line 中使用计算属性创建了一个字段。
niu = fields.Char(string="NIU", compute="_niu_validation", readonly=True, store=True)
@api.depends('product_id.product_tmpl_id.type')
def _niu_validation(self):
for rec in self:
if rec.product_id.product_tmpl_id.type == 'product' and not rec.niu:
rec.niu = self.env['ir.sequence'].next_by_code('sale.order.line')
这工作得很好,但同样想在 GUI Odoo 中做。
图片下方显示:http ://es.zimagez.com/zimage/computefield.php
但它向我显示以下错误:
ValueError: forbidden opcode(s) in u"for rec in self:\n if rec.product_id.product_tmpl_id.type == 'product' and not rec.niu:\n \t rec.niu = self.env['ir.sequence'].next_by_code('sale.order.line')"
也许存在语法错误,但我不知道如何在 GUI Odoo 中为字段定义方法。
欢迎任何帮助,建议,建议。如果有人可以帮助我,我将不胜感激。