Skip to Content

Contributors

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

by Holger Brunn - 09:41 - 13 Nov 2024

Reference

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

    Dear Contributors

     

           I have a question regarding the search for one2many fields and would like to seek assistance from the community.

          

           Odoo VersionCommunity 17.0+

          

           I created some products:

    l   Blue xxxsome_elsexx T-shirt

    l   Blue xxxsome_elsexx Desk

    l   White xxxsome_elsexx T-shirt

    l   White xxxsome_elsexx Desk

     

    Then, I randomly created some sales orders using these products. Now, if I want to search for the product "Blue xxxsome_elsexx Desk" within sales orders using this domain:

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

     

    I expect to get sales orders only containing the productBlue xxxsome_elsexx Desk

    However, the search results return sales orders containing Blue xxxsome_elsexx T-shirt and White xxxsome_elsexx Deskbut not those containing Blue xxxsome_elsexx Desk

     

    I am not sure if I have expressed this clearly. You can test the scenario with the sales orders I created in the runbot instance, and there are a few images to help with understanding.

    Testing environment on runbot: https://70500325-17-0-all.runbot143.odoo.com/web?debug=1#action=988&model=sale.order&view_type=list&cids=1&menu_id=660

     

     

     

     

           Thank you for your assistance.

    Best regards,

     

     

     

    feihu.zhang@live.com


    by feihu.zhang - 07:01 - 13 Nov 2024