Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How can I create an object from an onchange-method?

on 3/16/16, 11:23 AM 356 views


i tried to create an object from an onchange-method. The problem is, that i get following error, after creating the object:

Traceback (most recent call last):

File "/home/odoo/odoo/openerp/http.py", line 500, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/home/odoo/odoo/openerp/http.py", line 517, in dispatch

result = self._call_function(**self.params)

File "/home/odoo/odoo/openerp/http.py", line 283, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/home/odoo/odoo/openerp/service/model.py", line 113, in wrapper

return f(dbname, *args, **kwargs)

File "/home/odoo/odoo/openerp/http.py", line 280, in checked_call

return self.endpoint(*a, **kw)

File "/home/odoo/odoo/openerp/http.py", line 733, in __call__

return self.method(*args, **kw)

File "/home/odoo/odoo/openerp/http.py", line 376, in response_wrap

response = f(*args, **kw)

File "/home/odoo/odoo/addons/web/controllers/main.py", line 944, in call_kw

return self._call_kw(model, method, args, kwargs)

File "/home/odoo/odoo/addons/web/controllers/main.py", line 936, in _call_kw

return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)

File "/home/odoo/odoo/openerp/api.py", line 237, in wrapper

return old_api(self, *args, **kwargs)

File "/home/odoo/odoo/openerp/api.py", line 360, in old_api

result = method(recs, *args, **kwargs)

File "/home/odoo/odoo/openerp/models.py", line 5718, in onchange

record._onchange_eval(name, field_onchange[name], result)

File "/home/odoo/odoo/openerp/models.py", line 5648, in _onchange_eval

params = eval("[%s]" % params, global_vars, field_vars)

File "/home/odoo/odoo/openerp/tools/safe_eval.py", line 313, in safe_eval

return eval(c, globals_dict, locals_dict)

File "", line 1, in <module>

ValueError: "name 'parent_id' is not defined" while evaluating

'[use_parent_address, parent_id]'

Here is the code line which provide the object creation:

vals = {




'name': name,


self.pool['mail.mass_mailing.contact'].create(cr, uid, vals, context=context)

Can someone give me a hint how to fix that?

Hi Damien Bouvy, ty for this answer. Unlikely i have no Karma to comment your answer, but i voted for it =) So first ty for the hint. I waived to put all this into an onchange function. Now i got my solution with the write() method. The aim was to manage the marketinglists from the customer form^^

on 3/18/16, 4:22 AM
Damien Bouvy (dbo)
On 3/16/16, 4:58 PM

Ceating records from an onchange function is a really bad idea, since what is essentially a function that only works in cache is going to commit things in the db without you ever clicking the save button. You're probably better off overwriting write(), but even that can be tricky/dirty. Since I don't know what you're trying to do exactly, I can't give you more details really...

What seems wrong is that you seem to be calling the onchange_address without having set a parent_id on the partner. But without some context about what you want to do and your code, it's difficult to help you more than tat.


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 3/16/16, 11:23 AM
Seen: 356 times
Last updated: 3/17/16, 8:50 AM