我在GUI中创建一个字段Odoo有一个'compute'的方法。但我无法得到它。如何在GUI Odoo中的字段中定义计算?
我有一个在sale.py模块的sale.order.line中使用compute属性创建的字段。
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中的字段。
欢迎任何帮助,建议,建议。如果有人能帮助我,我将非常感激。
你尽量避免for循环?也许尝试只删除它,并只使用条件。 –
现在我收到以下错误: ValueError:“name'rec'未定义”评估 – beriliox
当我说要避免循环时,当然需要修改其余的代码! –