How to update a register other than the one that triggers a compute function - odoo

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).
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 binding 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!

Here are some ideas about your error.
main_endado_bind has been declared with char data type. So it always stores char values.
According to your code, it seems parent_external_id has integer value. And you are assigning integer values to char data type fields. So it doesn't work.
To resolve this issue, we have to explicitly type cast into char. For example,
product.main_endado_bind = str(parent_external_id)

Related

odoo plm module problem when create a new revision when i press start newrevision get error

plm module problem  when
create a new revision when i press start newrevision  get error 
Error:Odoo Server ErrorTraceback (most recent call last): File "/odoo/odoo/odoo/api.py", line 1049, in get value = self._data[key][field][record._ids[0]]KeyError: 1245During handling of the above exception, another exception occurred:Traceback (most recent call last): File "/odoo/odoo/odoo/fields.py", line 1065, in get value = record.env.cache.get(record, self) File "/odoo/odoo/odoo/api.py", line 1051, in get raise CacheMiss(record, field)odoo.exceptions.CacheMiss: ('mrp.bom(1245,).is_allowed_to_modif_unit', None)During handling of the above exception, another exception occurred:Traceback (most recent call last): File "/odoo/odoo/odoo/models.py", line 4765, in ensure_one _id, = self._idsValueError: too many values to unpack (expected 1)During handling of the above exception, another exception occurred:Traceback (most recent call last): File "/odoo/odoo/odoo/http.py", line 656, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/odoo/odoo/odoo/http.py", line 314, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/odoo/odoo/odoo/tools/pycompat.py", line 87, in reraise raise value File "/odoo/odoo/odoo/http.py", line 698, in dispatch result = self._call_function(**self.params) File "/odoo/odoo/odoo/http.py", line 346, in _call_function return checked_call(self.db, *args, **kwargs) File "/odoo/odoo/odoo/service/model.py", line 98, in wrapper return f(dbname, *args, **kwargs) File "/odoo/odoo/odoo/http.py", line 339, in checked_call result = self.endpoint(*a, **kw) File "/odoo/odoo/odoo/http.py", line 941, in call return self.method(*args, **kw) File "/odoo/odoo/odoo/http.py", line 519, in response_wrap response = f(*args, **kw) File "/odoo/odoo/addons/web/controllers/main.py", line 967, in call_button action = self._call_kw(model, method, args, {}) File "/odoo/odoo/addons/web/controllers/main.py", line 955, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/odoo/odoo/odoo/api.py", line 759, in call_kw return _call_kw_multi(method, model, args, kwargs) File "/odoo/odoo/odoo/api.py", line 746, in _call_kw_multi result = method(recs, *args, **kwargs) File "/odoo/Enterprise/mrp_plm/models/mrp_eco.py", line 586, in action_new_revision 'previous_bom_id': eco.bom_id.id, File "/odoo/odoo/odoo/models.py", line 4336, in copy new = self.with_context(lang=None).create(vals) File "", line 2, in create File "/odoo/odoo/odoo/api.py", line 440, in _model_create_single return create(self, arg) File "/odoo/mycompany/mrp_production_draft/models/mrp_production.py", line 954, in create res = super(MrpBom, self).create(values) File "", line 2, in create File "/odoo/odoo/odoo/api.py", line 461, in _model_create_multi return create(self, [arg]) File "/odoo/odoo/addons/mail/models/mail_thread.py", line 298, in create thread.message_track(tracked_fields, initial_values) File "/odoo/odoo/addons/mail/models/mail_thread.py", line 640, in message_track tracking = self._message_track_get_changes(tracked_fields, initial_values) File "/odoo/odoo/addons/mail/models/mail_thread.py", line 601, in _message_track_get_changes result[record.id] = record._message_track(tracked_fields, initial_values[record.id]) File "/odoo/odoo/addons/mail/models/mail_thread.py", line 618, in _message_track new_value = getattr(self, col_name) File "/odoo/odoo/odoo/fields.py", line 1069, in get self.determine_value(record) File "/odoo/odoo/odoo/fields.py", line 1182, in determine_value self.compute_value(recs) File "/odoo/odoo/odoo/fields.py", line 1136, in compute_value self._compute_value(records) File "/odoo/odoo/odoo/fields.py", line 1127, in _compute_value getattr(records, self.compute)() File "/odoo/mycompany/mrp_production_draft/models/mrp_production.py", line 945, in get_user self.is_allowed_to_modif_unit = True File "/odoo/odoo/odoo/fields.py", line 1084, in set record.ensure_one() File "/odoo/odoo/odoo/models.py", line 4768, in ensure_one raise ValueError("Expected singleton: %s" % self)ValueError: Expected singleton: mrp.bom(1245, 26)
plm module problem  when
create a new revision when i press start newrevision  get error and cannot add role and user empty i cannnot put anything on role

Odoo 10 - debug issue with mail template in sales order

I am getting this error when trying to send an email in sales order (quote).
When I dismiss the error message I get the modal window for sending email but no template has been selected and I have to select it manually. Then everything works fine
I hence suspect that the issue is that for some reason it is not getting the default template.
Any tips on how to fix this?
File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 640, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 677, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 333, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 101, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 326, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 935, in __call__
return self.method(*args, **kw)
File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 506, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python2.7/dist-packages/odoo/addons/web/controllers/main.py", line 885, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/usr/lib/python2.7/dist-packages/odoo/addons/web/controllers/main.py", line 877, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/usr/lib/python2.7/dist-packages/odoo/api.py", line 689, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "/usr/lib/python2.7/dist-packages/odoo/api.py", line 680, in call_kw_multi
result = method(recs, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/odoo/models.py", line 5491, in onchange
record._onchange_eval(name, field_onchange[name], result)
File "/usr/lib/python2.7/dist-packages/odoo/models.py", line 5389, in _onchange_eval
method_res = method(self)
File "/usr/lib/python2.7/dist-packages/odoo/addons/mail/wizard/mail_compose_message.py", line 342, in onchange_template_id_wrapper
values = self.onchange_template_id(self.template_id.id, self.composition_mode, self.model, self.res_id)['value']
File "/usr/lib/python2.7/dist-packages/odoo/addons/mail/wizard/mail_compose_message.py", line 364, in onchange_template_id
values = self.generate_email_for_composer(template_id, [res_id])[res_id]
File "/usr/lib/python2.7/dist-packages/odoo/addons/mail/wizard/mail_compose_message.py", line 501, in generate_email_for_composer
template_values = self.env['mail.template'].with_context(tpl_partners_only=True).browse(template_id).generate_email(res_ids, fields=fields)
File "/usr/lib/python2.7/dist-packages/odoo/addons/mail/models/mail_template.py", line 482, in generate_email
res_ids_to_templates = self.get_email_template(res_ids)
File "/usr/lib/python2.7/dist-packages/odoo/addons/mail/models/mail_template.py", line 423, in get_email_template
langs = self.render_template(self.lang, self.model, res_ids)
File "/usr/lib/python2.7/dist-packages/odoo/addons/mail/models/mail_template.py", line 380, in render_template
records = self.env[model].browse(filter(None, res_ids)) # filter to avoid browsing [None]
File "/usr/lib/python2.7/dist-packages/odoo/api.py", line 760, in __getitem__
return self.registry[model_name]._browse((), self)
File "/usr/lib/python2.7/dist-packages/odoo/modules/registry.py", line 174, in __getitem__
return self.models[model_name]
KeyError: False
I found an answer here:
Odoo Support forum - Change Default Mail Template
I changed the template (duplicate and deleted the original one) so you have to change the ID which refers to old one.

Odoo issue : missing record does not exist or has been deleted

In Quotation => New
Select customer => Search more
result => Odoo Error : missing record does not exist or has been deleted
POST http://example.net/web/dataset/call_kw/res.partner/name_search 200 OK :
"Traceback (most recent call last):
File "/mnt/odoo-source/odoo/http.py", line 640, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/mnt/odoo-source/odoo/http.py", line 677, in dispatch
result = self._call_function(**self.params)
File "/mnt/odoo-source/odoo/http.py", line 333, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/mnt/odoo-source/odoo/service/model.py", line 101, in wrapper
return f(dbname, *args, **kwargs)
File "/mnt/odoo-source/odoo/http.py", line 326, in checked_call
result = self.endpoint(*a, **kw)
File "/mnt/odoo-source/odoo/http.py", line 935, in __call__
return self.method(*args, **kw)
File "/mnt/odoo-source/odoo/http.py", line 506, in response_wrap
response = f(*args, **kw)
File "/mnt/odoo-source/addons/web/controllers/main.py", line 885, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/mnt/odoo-source/addons/web/controllers/main.py", line 877, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/mnt/odoo-source/odoo/api.py", line 679, in call_kw
return call_kw_model(method, model, args, kwargs)
File "/mnt/odoo-source/odoo/api.py", line 664, in call_kw_model
result = method(recs, *args, **kwargs)
File "/mnt/odoo-source/odoo/addons/base/res/res_partner.py", line 681, in name_search
return super(Partner, self).name_search(name, args, operator=operator, limit=limit)
File "/mnt/odoo-source/odoo/models.py", line 1600, in name_search
return self._name_search(name, args, operator, limit=limit)
File "/mnt/odoo-source/odoo/models.py", line 1615, in _name_search
return recs.sudo(access_rights_uid).name_get()
File "/mnt/odoo-source/odoo/addons/base/res/res_partner.py", line 586, in name_get
name = name + "\n" + partner._display_address(without_company=True)
File "/mnt/odoo-source/odoo/addons/base/res/res_partner.py", line 781, in _display_address
address_format = self.country_id.address_format or \
File "/mnt/odoo-source/odoo/fields.py", line 866, in __get__
value = record._cache[self]
File "/mnt/odoo-source/odoo/models.py", line 5562, in __getitem__
return value.get() if isinstance(value, SpecialValue) else value
File "/mnt/odoo-source/odoo/fields.py", line 48, in get
raise self.exception
MissingError: (u'Enregistrement inexistant ou d\xe9truit.', None)
"
I'm stuck with this issue. Anyone know what could i do ?
The issue is solved.
"Country_id" field in "res_partner" table was referencing an unexisting country in "res_country table".

How can override a field default value with default_get in odoo9?

I want to override the default value for a field with the default_get API function in odoo9.
I have this in my code:
#api.model
def default_get(self, fields_list):
res = super(hr_attendance, self).default_get(fields_list)
res.update({
'animal': 'dog'
})
return res
When I create a new register, this error appears in the odoo log:
2016-09-02 11:33:36,680 27542 ERROR mydb openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
File "/etc/odoo/server/openerp/http.py", line 648, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/etc/odoo/server/openerp/http.py", line 685, in dispatch
result = self._call_function(**self.params)
File "/etc/odoo/server/openerp/http.py", line 321, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/etc/odoo/server/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/etc/odoo/server/openerp/http.py", line 314, in checked_call
result = self.endpoint(*a, **kw)
File "/etc/odoo/server/openerp/http.py", line 964, in __call__
return self.method(*args, **kw)
File "/etc/odoo/server/openerp/http.py", line 514, in response_wrap
response = f(*args, **kw)
File "/etc/odoo/server/addons/web/controllers/main.py", line 888, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/etc/odoo/server/addons/web/controllers/main.py", line 880, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/etc/odoo/server/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/etc/odoo/server/openerp/api.py", line 354, in old_api
result = method(recs, *args, **kwargs)
File "/etc/odoo/server/addons_extra/hr_attendance_extend/hr_attendance.py", line 79, in default_get
res.update({
AttributeError: 'tuple' object has no attribute 'update'
What I am doing wrong?
Edit: I had another variable with the same name which provoqued conflict.
Renaming the variable, everything works perfect.
update is a method of dictionary data-type. And you are trying to use it with tuple data-type. That's reason you got error.
Try with following code:
#api.model
def default_get(self, fields):
res = super(hr_attendance, self).default_get(fields)
res['animal'] = 'dog'
return res

odoo IndexError: list index out of range

Any ideas on the following odoo error? I Installed the Accounting module and instead of modifying the default Sales and Purchase Taxes entries ODOO created, made my own and deleted theirs. This error started happening when I try accessing different parts of the accounting module. I could try to reinstall the module but have had bad experiences with that.
Odoo Server Error
Traceback (most recent call last):
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/http.py", line 646, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/http.py", line 683, in dispatch
result = self._call_function(**self.params)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/http.py", line 319, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/http.py", line 312, in checked_call
result = self.endpoint(*a, **kw)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/http.py", line 962, in __call__
return self.method(*args, **kw)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/http.py", line 512, in response_wrap
response = f(*args, **kw)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/addons/web/controllers/main.py", line 897, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/addons/web/controllers/main.py", line 889, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/api.py", line 381, in old_api
result = method(recs, *args, **kwargs)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/models.py", line 6054, in onchange
record._onchange_eval(name, field_onchange[name], result)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/models.py", line 5911, in _onchange_eval
method_res = method(self)
File "/opt/odoo-9.0.20160620-2/apps/odoo/lib/odoo-9.0rc20160620-py2.7.egg/openerp/addons/account/models/res_config.py", line 169, in onchange_company_id
self.default_sale_tax_id = isinstance(taxes_id, list) and taxes_id[0] or taxes_id
IndexError: list index out of range
This was a bug that was fixed on commit 1d843884e861252e395e0818b0fbf8aa074cd9d2.
Do a git pull on your branch to update your server files,restart the server and try again.
The problem is that in "res_config.py" you have a list you work with the first element is probably empty
To avoid this problem, you can use taxes_id[0] inside if taxes_id: