Skip to Content
Menu
This question has been flagged
1 Reply
9025 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.?

Avatar
Discard
Best Answer

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}}


Avatar
Discard
Author

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.

Author

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'))]

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.

Author

Thanks Sarga. it will work,