Odoo Help


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

on 3/16/16, 11:23 AM 1,260 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)

--Damien Bouvy (dbo)--

| 1 0 1
Grand-Rosière, Belgium
--Damien Bouvy (dbo)--

Damien is part of the Odoo R&D department. He has taken part in the development of several features in Odoo, including the Subscription application, the Sales application, the frontend portal and the payment acquirers.

Nowadays he commits on our internal codebase, maintaining the billing process of Odoo.com, developing external tools and internal processes. More recently, he took part in the development of the Odoo.sh platform.

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.


About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


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