Skip to Content
Menu
This question has been flagged

Hello,


I am under Odoo 17 and using its external API .

I successfully fetch the products from database with a filter on product category.

However, I am interested in filtering them by using several criteria with "AND" operator.

When I simply add multiple criteria, it implicitly works as an OR operator.

In my "search_read" request, my filter look like this (json format for our convenience)

[[["categ_id","in",[37]],["quantity_svl",">","0"],["lst_price","

Meaning : Find product that are in category 37 (OR) with quantity_svl greater than 0, (OR) lst_price lower or equal to 2


After some research, i have found and tested an old post (xml-rpc-api-object-search-mixing-and-and-or-58468) 

Witch transform my filter to this

[["&","&",["categ_id","in",[37]],["quantity_svl",">","0"],["lst_price","

and should mean : Find product that are in category 37 AND with quantity_svl greater than 0, AND lst_price lower or equal to 2


There is no error but the results are the same. Maybe it is obsolete?


My question is : do someone knows the correct way to use AND operator for filtering products in "search_read" requests ?


Thanks for your help !


To summary, my request look like this


	
$filters = [
        'search' => [[
​'&',
​'&',
['categ_id', 'in', [37,15, etc...]],
​​['quantity_svl', ' ​['lst_price', ' ​]],
        'display' => [
            'offset' => 0,
            'limit' => 12,
            'fields' => ['name', 'image_512', 'lst_price', 'image_512', 'categ_id', 'quantity_svl', 'default_code', 'active', 'barcode'],
        ]
    ];

$models->execute_kw(ODOO_DB, $uid, ODOO_PASSWORD, 'product.product', 'search_read', $filters['search'], $filters['display']);





Avatar
Discard
Author Best Answer

I found the solution,

The issue was not the syntax but rather the fields names.

Indeed, in order to filter by price I  I was looking at "lst_price" instead of "list_price".


I got "lst_price" from a var_dump of a a search_read's result. But this field is actually ignored when fed in a query.

Same for many other fields.

Same for their types.

The var_dump of a a search_read's result will show that list_price is supposed to be an array, and you might then assume that it is an array of prices (hence "list_price"). But after looking in Odoo / Technical / User-defined Filters (see source), you will see that "list_price" is a float.


Source :

I have not enough karma to share links, so search for "Odoo tricks and tips Create a user-defined filter"


Avatar
Discard
Related Posts Replies Views Activity
0
Dec 23
854
2
Mar 25
5548
0
Dec 24
754
2
Sep 24
1119
0
Sep 24
570