Odoo Help

Welcome!

This community 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.

0

XML-RPC API - object/search mixing AND and OR?

By
Jason Judge
on 7/24/14, 12:04 PM 1,103 views

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

AND (

    (module = base AND name = my_id_1)

    OR

    (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?

Thanks.

Answer

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).

Thanks Ray - polish notation works a charm :-)

Jason Judge
on 7/24/14, 7:21 PM
1

Ray Carnes

--Ray Carnes--
15717
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0 and Odoo 8.0, 9.0 (Since 2012)

Completed Functional and Technical Training.

Major Skills:

  • Needs Discovery and Requirements Analysis;

  • Function and Technical Specifications;

  • Project Planning;

  • Prototyping and Proof of concepts;

  • Data migration;

  • Configuration & Customization (UI and modules);

  • Integration - data, business logic and service levels;

  • Training and Knowledge transfer;

  • Go Live support;

  • Help desk;

  • Version Migration.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

Ray Carnes
On 7/24/14, 2:09 PM

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

 

Your Answer

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/24/14, 12:04 PM
Seen: 1103 times
Last updated: 3/16/15, 8:10 AM