Odoo Help

Welcome!

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.

0

how can we set multiple conditions in domain?

By
Apoorv Soral
on 11/16/16, 4:52 AM 146 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.?

1
Sarga
On 11/16/16, 9:22 AM

Hi ,

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

@api.onchange('del_states')

def onchange(self):

domain=[]

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([

('pending','Pending'),

('done','Done'),

('all','All'),

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

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

@api.onchange('del_states')

def onchange(self):

domain=[]

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.

Sarga
on 11/17/16, 10:13 AM

Thanks Sarga. it will work,

Apoorv Soral
on 11/18/16, 1:49 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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/16/16, 4:52 AM
Seen: 146 times
Last updated: 11/18/16, 1:49 AM