【问题标题】:How to update a register other than the one that triggers a compute function如何更新触发计算功能的寄存器以外的寄存器
【发布时间】:2021-06-08 07:37:26
【问题描述】:

我想获取产品绑定并在视图中显示它(这可行)。如果它没有绑定,我必须检查该产品是否是物料清单的一部分,如果是,我必须查找父级的绑定并显示该绑定(这是行不通的,它没有' 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, *args, **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, **kw)
File "/mnt/environment/odoo-server/odoo/http.py", 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], method, args, kwargs)
File "/mnt/environment/odoo-server/odoo/api.py", line 756, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "/mnt/environment/odoo-server/odoo/api.py", line 743, in call_kw_multi
result = method(recs, *args, **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", line 5096, 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 = 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

KeyError: 79 是 bom 行的 id。

有什么想法吗?谢谢!

【问题讨论】:

    标签: odoo odoo-10 odoo-11


    【解决方案1】:

    以下是关于您的错误的一些想法。

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

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

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

    product.main_endado_bind = str(parent_external_id)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-16
      • 1970-01-01
      • 2019-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-26
      相关资源
      最近更新 更多