Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

回复: Assistance Needed: Searching for Specific Products in Sales Orders (Odoo CE 17.0+)

by
feihu.zhang
- 13/11/2024 10:18:18

Hi Holger

 

Thank you very much for your response; it was of great help to me.

 

Further, is it possible to use multiple layered search criteria in the search view to make the operation more user-friendly?

For example: 

The user first searches for products containing "blue": [("order_line.product_id", "any", [("name", "ilike", "blue")])]

Then, the user searches again for products containing "desk": [("order_line.product_id", "any", [("name", "ilike", "blue"),("name", "ilike", "desk")])]

Finally, the user searches again for products containing "small": [("order_line.product_id", "any", [("name", "ilike", "blue"),("name", "ilike", "desk"),("name", "ilike", "small")])]

 

       Thank you for your guidance.

Best regards,

      

      

 

发件人: Holger Brunn <notifications@odoo-community.org>
发送时间: 2024-11-13 16:43
收件人: Contributors <contributors@odoo-community.org>
主题: Re: Assistance Needed: Searching for Specific Products in Sales Orders (Odoo CE 17.0+)

 

> [("order_line.product_id.name", "ilike",

 

> "blue"),(("order_line.product_id.name", "ilike", "desk"))]

 

> 

 

> 

 

> I expect to get sales orders only containing the product*Blue xxxsome_elsexx

 

> Desk*

 

this expectation is wrong. Your domain evaluates to something like

 

select id

from sale_order

where

exists (

  select id from order_line ...

  where .... name like '%blue%'

)

and

exists (

  select id from order_line ...

  where .... name like '%desk%'

)

 

so any order having some (not necessarily the same) order line satisfying your 

conditions will be returned.

 

What you need is the any operator that was introduced in v17:

https://www.odoo.com/documentation/17.0/developer/reference/backend/

orm.html#search-domains

 

 [("order_line.product_id", "any", [("name", "ilike", "blue"),("name", 

"ilike", "desk")])]

 

and before v17 you were just out of luck trying to express such a condition 

with a domain.

 

If you also want to exclude orders with order lines not fitting your condition, 

you need to add a "not any" clause.

 

 

-- 

Your partner for the hard Odoo problems

https://hunki-enterprises.com

Reference