This question has been flagged
5 Replies
13532 Views

sale_list = self.env['sale.order'].search('|',             

                                  ( ['&',('id','in',self.sale_id_all.ids),('partner_id','in',self.cust_id.ids)]  ),                                                         

                                   (  [('id','in',self.sale_id_all.ids)]  ),

                                   (  [('partner_id','in',self.cust_id.ids)]  ),

                                   (  [('state','in',al)]  )

)




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 948, in call_button    action = self._call_kw(model, method, args, {})  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)  File "/home/pchouksey1/workspace/dexciss/core/openerp/api.py", line 268, in wrapper    return old_api(self, *args, **kwargs)  File "/home/pchouksey1/workspace/dexciss/core/openerp/api.py", line 399, in old_api    result = method(recs, *args, **kwargs)  File "/home/pchouksey1/workspace/dexciss/repo/delivery_performance/wizard/delivery_performance.py", line 301, in out_picking    ([('state','in',al)])  File "/home/pchouksey1/workspace/dexciss/core/openerp/api.py", line 266, in wrapper    return new_api(self, *args, **kwargs)  File "/home/pchouksey1/workspace/dexciss/core/openerp/api.py", line 508, in new_api    result = method(self._model, cr, uid, *args, **old_kwargs)TypeError: search() got multiple values for keyword argument 'context'



how to set filter in multiple m2m field?

Avatar
Discard
Best Answer

Hello Apporv,

Actually the domain syntax is wrong in the above code, that is the reason why you are facing this error.

In domain, you need to pass list of tuples.

Example code,

self.env['res.partner'].search([('customer','=',True)])


By default the domain  adds a 'AND' condition by default. You can add an 'Or' condition as bellow,

self.env['res.partner'].search(['|',('customer','=',True),('email','!=',False)])


Hope this helps,

Thank You.


Avatar
Discard
Author

Hi Burhan,

thanks for help but

actually i want to set filter according to recrods

if we select only cust(m2m) so (saleorder and cust) is false or (saleorder) is false but (cust) True so filter all cust

and if we select saleorder and cust so filter and so those records.

it means.

i want to set multiple & and multiple |(or) in single search method

Is It possible so how?

Author Best Answer

This is m code -


I want to apply "and" on three(or more) statements together... Like sale_id_all and cust_id and saleperson_id,etc.


sale_list = self.env['sale.order'].search(['|','|','|', '&', ('id','in',self.sale_id_all.ids), ('partner_id','in',self.cust_id.ids),('user_id','in',self.sales_person_id.ids),                                                              ('id','in',self.sale_id_all.ids),('partner_id','in',self.cust_id.ids),('user_id','in',self.sales_person_id.ids)                                                             ])

Avatar
Discard
Best Answer

Hello Apoorv,

sale_list = self.env['sale.order'].search( ['|', '&', ('id','in',self.sale_id_all.ids), ('partner_id','in',self.cust_id.ids), '&', '&', ('id','in',self.sale_id_all.ids), ('partner_id','in',self.cust_id.ids), ('state','in',al) ] )

I hope this can be helpful to you.


Avatar
Discard
Author

It sure was helpful. Let me make it more interesting for you -

I want to apply domain like this - ((if customer id exists, then search all records which matches customer id selected in m2m) or (search all customer id))

and

((if saleorder id exists, then search all records which matches saleorder id selected in m2m) or (search all saleorder id))