Odoo Help


how can we set multiple conditions in domain?

Apoorv Soral
on 11/16/16, 4:52 AM 320 views

<field name="sale_id_all" widget = "many2many_tags" attrs="{'invisible': ['|',('del_states','!=','all'),('saleorder_checkbox','!=',True)]}"  domain = "[('state','not in',('draft','cancel'))]"/>

in same code if condition ('del_states','!=',done)

domain = "[('state','=','done')]",

if condition ('del_states','!=','pending')

domain = "[('state','not in',('draft','cancel','done'))]"  

 i want to change domain according to conditions how can i set multiple domain or any other way to solve this problem.?

On 11/16/16, 9:22 AM

Hi ,

in py file for the model just define onchange function for del_states


def onchange(self):


if self.del_states != 'done':

domain= [('state','=','done')]

# define domain as per condition and at last

return {'domain':{'sale_id_all':domain}}

Traceback (most recent call last):

File "/home/pchouksey1/workspace/dexciss/core/openerp/http.py", line 543, in _handle_exception

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

File "/home/pchouksey1/workspace/dexciss/core/openerp/http.py", line 580, in dispatch

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

File "/home/pchouksey1/workspace/dexciss/core/openerp/http.py", line 316, in _call_function

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

File "/home/pchouksey1/workspace/dexciss/core/openerp/service/model.py", line 118, in wrapper

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

File "/home/pchouksey1/workspace/dexciss/core/openerp/http.py", line 313, in checked_call

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

File "/home/pchouksey1/workspace/dexciss/core/openerp/http.py", line 809, in __call__

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

File "/home/pchouksey1/workspace/dexciss/core/openerp/http.py", line 409, in response_wrap

response = f(*args, **kw)

File "/home/pchouksey1/workspace/dexciss/core/addons/web/controllers/main.py", line 944, in call_kw

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

File "/home/pchouksey1/workspace/dexciss/core/addons/web/controllers/main.py", line 936, in _call_kw

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

TypeError: onchange() takes exactly 1 argument (8 given)

i'm trying as you write above onchange method but when we select state in the del_state field it's giving this error.

Apoorv Soral
on 11/17/16, 1:17 AM

Hi Sarga,

In .xml

<field name="del_states" widget = "selection" attrs="{'invisible': [('states_checkbox','!=',True)]}"/>

<field name="sale_id_all" widget = "many2many_tags" attrs="{'invisible': [('saleorder_checkbox','!=',True)]}"/>

In .py

del_states = fields.Selection([




],'States',default = 'all')

sale_id_all = fields.Many2many('sale.order',string = 'Sale Order')


def onchange(self):


if self.del_states != 'done':

domain= [('state','=','done')]

if self.del_states != 'pending':

domain= [('state','not in',('draft','cancel','done'))]

if self.del_states != 'all':

domain= [('state','not in',('draft','cancel'))]

Apoorv Soral
on 11/17/16, 1:22 AM

Hi apoorv,

I tried creating two similar fields as in your py and for me it worked fine . Does it make an entry into the onchange function?

Just rename the onchange function as def _onchange_state.

on 11/17/16, 10:13 AM

Thanks Sarga. it will work,

Apoorv Soral
on 11/18/16, 1:49 AM

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: 11/16/16, 4:52 AM
Seen: 320 times
Last updated: 11/18/16, 1:49 AM