我在GUI中创建了一个字段,Odoo有一个带有'compute‘的方法。但是我拿不到。
我使用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中的字段定义方法。
欢迎任何帮助,建议,建议。如果有人能帮助我,我将不胜感激。
发布于 2017-01-22 01:51:24
解决方案是使用类似字典的赋值来赋值,而不是使用self赋值。注释,例如:
 self.x_hora_estimada_llegada = self.date_order将抛出
U中的
禁止操作码....
但是相反,您使用类似字典的赋值,您的字段将会很好!:
for record in self:
    record['x_hora_estimada_llegada'] = self.date_order发布于 2016-03-01 21:21:05
我不使用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-07-04 21:59:02
亲爱的们:
我也遇到过类似的问题,你可以试试
if self.product_id.product_tmpl_id.type ==‘==’而不是self.niu: self.'niu‘=
https://stackoverflow.com/questions/35722344
复制相似问题