Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
The documentation shows the search criteria of a search being a list of tuples, which are all ANDed together. Is there a way, through the API, to use more complex mixes of AND and OR. For example, given the two external IDs base.my_id_1 and l10n_uk.my_id_2, to search for both of these at the same time, I would need to search the ir.module.data model for:
model = whatever.searching.model
(module = base AND name = my_id_1)
(module = l10n_uk AND name = my_id_2)
Can that be done through the API on one call to object/search? Or would I need to do two searches - one for each module - and merge the results together?
Ray pointed the answer to a previous post which shows how polish notation is used. For my above example, the "(module = base AND name = my_id_1)" criteria is represented by the following elements in the criteria array (in PHP, as that's what I'm using):
["module", "=", "base"],
["name", "=", "my_id_1"]
This can be repeated as many times as needed, say N times.
Now to OR these together, the above array is prepended with N-1 "|" elements. So the full example from above, with N=2, would look like this:
["module", "=", "base"],
["name", "=", "my_id_1"],
["module", "=", "l10n_uk"],
["name", "=", "my_id_2"],
That's very easy to knock up programmatically for any value of N (just a few lines like this https://github.com/academe/openerpapi/blob/master/src/Interfaces/Object.php#L215). Additional criteria elements can be prepended (and I assume appended) to that, and they don't seem to need "&"s of their own. So the criteria does not need to be strcitly 100% polish, as the "&" operator is assumed where no operator is given, and that is how not using any "&" or "|" elements at all works anyway.
Thanks :-) Hope that's helpful to others. In all my years of coding, this is the first time I have actually had to use polish notation, and it seems fun. I would recommend anyone wanting to do this read follow your links and see how it works - my example above is not the general solution, but the application of the polish notation to my specific case, which is all data-driven (I've just plugged in the specific example values for illustration).
Just create the appropriate domain for your search, combining any number of AND's and OR's.
My method is explained in https://www.odoo.com/forum/help-1/question/domain-notation-using-multiple-and-nested-and-2170
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 7/24/14, 12:04 PM|
|Seen: 1163 times|
|Last updated: 3/16/15, 8:10 AM|