Skip to Content
Menu
This question has been flagged
1328 Views

Hello,

I want to get the product binding and show it in a view (this works). If it has no binding I have to check if that product is part of a bill of materials and if it is, I have to look for the binding of the parent and show that binding (this is what doesn't work, it doesn't give error but it doesn't assign the value of the parent to the child). 

Code:

```

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

```

When modifying a BOM I want to assign the id of the parent to the new material but it is the parent that triggers the compute as it is its BOM that is modified.


If instead of the last line I use a write I get this error:

```

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

```

The KeyError: 79 is the id of the bom line.


Any idea? Thanks!

Avatar
Discard