1

我在 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 中为字段定义方法。

欢迎任何帮助,建议,建议。如果有人可以帮助我,我将不胜感激。

4

3 回答 3

4

解决方案是使用类似字典的赋值而不是 self. 注释,例如:

 self.x_hora_estimada_llegada = self.date_order

会扔

u....中禁止的操作码

但是相反,您使用类似字典的分配,您的字段就可以了!:

for record in self:
    record['x_hora_estimada_llegada'] = self.date_order
于 2017-01-21T17:51:24.443 回答
1

我不使用 v9,所以我认为你只需要做一些试验和错误。

试试这个:

    if self.product_id.product_tmpl_id.type == 'product' and not self.niu:
            self.niu = self.env['ir.sequence'].next_by_code('sale.order.line')

如果它不起作用,也许尝试:

    if self.product_id.product_tmpl_id.type == 'product' and not self.niu:
            return self.env['ir.sequence'].next_by_code('sale.order.line')
于 2016-03-01T13:21:04.747 回答
0

亲爱的,

我也遇到过类似的问题,你可以试试

如果 self.product_id.product_tmpl_id.type == 'product' 而不是 self.niu: self.['niu'] = self.env['ir.sequence'].next_by_code('sale.order.line')

于 2016-07-04T13:59:02.213 回答