Odoo Help


Using onchange with 2 dropdown menus, it is possible?

on 5/15/15, 3:44 AM 560 views


I am trying to use the @api.onchange with two dropdown menus and although I am not getting any errors, it is not working how I would like.

I have 2 fields created:

"status_id": fields.many2one("profile.status", "Kontaktstatus"),

"phase_id": fields.many2one("profile.phase", "Phase"),

and I would like that when I change the phase_id that the status_id will change automatically based on what is selected. Here is my def code:


def do_stuff(self):

if self.phase_id != '':

    if self.phase_id == "Kontaktphase":

        self.status_id == "Interessant"

    elif self.phase_id == "Präsentationphase":

        self.status_id == "Kandidat"

    elif self.phase_id == "Testphase":

        self.status_id == "Kandidat"

    elif self.phase_id == "Angebotsphase":

        self.status_id == "Kandidat"

What am I doing wrong here?

Saravanan Sakthivel
On 5/15/15, 4:17 AM


You are using many2one field here ("status_id","phase_id").So You cant compare id (many2one field) with string .

Try to comapre with many2one field name with string value.

Ex :-

if self.phase_id.name == "Kontaktphase":

and return your value using below code

result['value']['status_id'] = ID value of "Interessant"

Thanks Saravanan Tried the above and I got the following error: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 530, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 567, in dispatch result = self._call_function(**self.params) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 303, in _call_function return checked_call(self.db, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper return f(dbname, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 300, in checked_call return self.endpoint(*a, **kw) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 796, in __call__ return self.method(*args, **kw) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 396, in response_wrap response = f(*args, **kw) File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 936, in call_kw return self._call_kw(model, method, args, kwargs) File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 928, in _call_kw return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 363, in old_api result = method(recs, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 5846, in onchange record._onchange_eval(name, field_onchange[name], result) File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 5727, in _onchange_eval method_res = method(self) File "/home/vagrant/addons/profile/profile.py", line 78, in do_stuff result['value']['status_id'] = "Interessant" NameError: global name 'result' is not defined

on 5/15/15, 4:39 AM

define variable in the top of function result = {'value': { }}

Saravanan Sakthivel
on 5/15/15, 5:03 AM

Plz check above answer ,I have edited.

Saravanan Sakthivel
on 5/15/15, 5:13 AM

Thank Saravanan, I must been doing something very wrong as it is not liking the sytax or the "ID value of" in the above code. @api.onchange('phase_id') result = {'value': { }} def do_stuff(self): if self.phase_id != '': if self.phase_id.name == "Kontaktphase": result['value']['status_id'] = ID value of "Interessant" When I put result inside the function, it says it should be a global variable.

on 5/18/15, 2:04 AM

Hi,then Just define global variable as result = {'value': {'status_id':False}}

Saravanan Sakthivel
on 5/19/15, 4:55 AM

I am now back to original error: Syntax error on this line: result['value']['status_id'] = ID value of "Interessant"

on 5/20/15, 2:31 AM

Any other ideas on this as this is still not working

on 5/29/15, 5:33 AM

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 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: 5/15/15, 3:44 AM
Seen: 560 times
Last updated: 5/15/15, 5:12 AM