微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何更新触发计算功能的寄存器以外的寄存器

如何解决如何更新触发计算功能的寄存器以外的寄存器

我想获取产品绑定并将其显示在视图中(这有效)。如果它没有绑定,我必须检查该产品是否是物料清单的一部分,如果是,我必须查找父级的绑定并显示该绑定(这是行不通的,它不起作用) t 给出错误,但它不会将父级的值分配给子级)。

class ProductProduct(models.Model):
    _inherit = 'product.product'

    main_endado_bind = fields.Char(
        string='Main Endado Bind',store=True,compute='_get_endado_bind'
    )

    @api.multi
    @api.depends('endado_bind_ids','bom_ids.bom_line_ids')
    def _get_endado_bind(self,external_id=''):
        for product in self:
            if product.endado_bind_ids:
                parent_external_id = product.endado_bind_ids[0].external_id
                product.main_endado_bind = parent_external_id
                for line_product in product.bom_ids.bom_line_ids:
                    line_product.product_id._get_endado_bind(external_id=parent_external_id)
            elif external_id:
                product.main_endado_bind = external_id

修改 BOM 时,我想将父项的绑定 ID 分配给新材料,但触发计算的是父项,因为修改的是其 BOM。

如果我使用 write 而不是最后一行,则会出现此错误


Error:
odoo Server Error
Traceback (most recent call last):
File "/mnt/environment/odoo-server/odoo/fields.py",line 967,in __get__
value = record.env.cache.get(record,self)
File "/mnt/environment/odoo-server/odoo/api.py",line 1041,in get
value = self._data[key][field][record._ids[0]]
KeyError: 79
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "/mnt/environment/odoo-server/odoo/http.py",line 653,in _handle_exception
return super(JsonRequest,self)._handle_exception(exception)
File "/mnt/environment/odoo-server/odoo/http.py",line 312,in _handle_exception
raise pycompat.reraise(type(exception),exception,sys.exc_info()[2])
File "/mnt/environment/odoo-server/odoo/tools/pycompat.py",line 87,in reraise
raise value
File "/mnt/environment/odoo-server/odoo/http.py",line 695,in dispatch
result = self._call_function(**self.params)
File "/mnt/environment/odoo-server/odoo/http.py",line 344,in _call_function
return checked_call(self.db,*args,**kwargs)
File "/mnt/environment/odoo-server/odoo/service/model.py",line 97,in wrapper
return f(dbname,**kwargs)
File "/mnt/environment/odoo-server/odoo/http.py",line 337,in checked_call
result = self.endpoint(*a,**kw)
File "/mnt/environment/odoo-server/odoo/http.py",line 939,in __call__
return self.method(*args,line 517,in response_wrap
response = f(*args,**kw)
File "/mnt/develop/odoo-server/addons/web/controllers/main.py",line 935,in call_kw
return self._call_kw(model,method,args,kwargs)
File "/mnt/develop/odoo-server/addons/web/controllers/main.py",line 927,in _call_kw
return call_kw(request.env[model],kwargs)
File "/mnt/environment/odoo-server/odoo/api.py",line 756,in call_kw
return call_kw_multi(method,model,line 743,in call_kw_multi
result = method(recs,**kwargs)
File "/mnt/develop/odoo-server/addons/mail/models/mail_thread.py",line 283,in write
result = super(MailThread,self).write(values)
File "/mnt/environment/connector/component_event/models/base.py",line 102,in write
result = super(Base,self).write(vals)
File "/mnt/environment/odoo-server/odoo/models.py",line 3208,in write
self._write(store_vals)
File "/mnt/environment/odoo-server/odoo/models.py",line 3430,in _write
self.recompute()
File "/mnt/environment/odoo-server/odoo/models.py",line 5096,in recompute
vals = {n: rec[n] for n in ns}
File "/mnt/environment/odoo-server/odoo/models.py",in
vals = {n: rec[n] for n in ns}
File "/mnt/environment/odoo-server/odoo/models.py",line 4944,in __getitem__
return self._fields[key].__get__(self,type(self))
File "/mnt/environment/odoo-server/odoo/fields.py",line 974,in get
value = self._data[key][field][record._ids[0]]
KeyError: 79

KeyError: 79 是 bom 行的 id。

有什么想法吗?谢谢!

解决方法

这里有一些关于您的错误的想法。

main_endado_bind 已声明为 char 数据类型。所以它总是存储字符值。

根据您的代码,似乎 parent_external_id 具有整数值。您正在为 char 数据类型字段分配整数值。所以它不起作用。

要解决这个问题,我们必须显式地将类型转换为 char。例如,

product.main_endado_bind = str(parent_external_id)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。