Odoo Help


Domain notation using multiple and nested '|' and '&'

Ray Carnes
on 2/18/13, 3:29 PM 24,163 views

OpenERP 7.0

I have read http://christophe-simonis-at-tiny.blogspot.com/2008/08/new-new-domain-notation.html

I can't work out how to translate the following:

( A OR B ) AND ( C OR D OR E )

I'd appreciate both the answer as well as a method I can use to get the answer myself next time.

The post above gives this example: [ '|' , '|' , ('state', '=', 'open') , ('state', '=', 'closed') , ('state', '=', 'draft') ]

I am assuming this is ( A OR B OR C ).

So my guess is what I need is:

[ '&' , '|' , (A) , (B) , '|' , '|' , (C) , (D) , (E) ]

and my second guess is:

[ '&' , '|' , (A) , (B) , '|' , (C) , '|' , (D) , (E) ]

are these the same?

I'd rather not guess or assume, and rather not test, I'd like to KNOW!

How does the expression get parsed? Does it start from the right?



Ahmet Altinisik

--Ahmet Altinisik--
| 8 7 10
ANKARA, Turkey
--Ahmet Altinisik--


Ahmet Altinisik
On 2/18/13, 5:37 PM

OpenERP uses Polish Notation for Domain filters.

First you should understand what is polish notation. You can find detailed information in wikipedia about polish notation. http://en.wikipedia.org/wiki/Polish_notation

About your question

( A OR B ) AND ( C OR D OR E )

should converted to the polish notation as


And should be solved by the algorithm with following order [] represents operation

AND [OR A B] OR OR C D E         Result of [OR A B] is F

AND F OR [OR C D] E              Result of [OR C D] is G

AND F [OR G E]                   Result of [OR G E] is H


it starts from LEFT to Right.

"If another operator is found before two operands are found, then the old operator is placed aside until this new operator is resolved. This process iterates until an operator is resolved, which must happen eventually, as there must be one more operand than there are operators in a complete statement." From wikipedia article.

you can also use in operator instead of writing three separate tuples with OR operator like

['&',('field2', 'in', ['A', 'B']),('state', 'in', ['open', 'closed', 'draft'])]

you can check the various use of the domain filters in the actions list from

Settings > Actions > Window Actions (technical features should be on)

Thanks! I did read that Wikipedia article. When I read 'the result is a syntax lacking parentheses or other brackets that can still be parsed without ambiguity' I figured you were not supposed to use parentheses! Isn't the arity of & and | fixed ?

Bista Solutions US, Ray Carnes
on 2/18/13, 5:50 PM

I was looking at AND(OR A B)(OR C OR D E) when I made that comment. Can that be written as AND OR A B OR C OR D E

Bista Solutions US, Ray Carnes
on 2/18/13, 6:18 PM

Just corrected my answer please read it again,

Altınkaya Elektronik Cihaz Kutuları imalat Ticaret ltd sti, Ahmet Altinisik
on 2/19/13, 3:17 AM

So does that mean AND OR A B OR C OR D E is also acceptable?

Bista Solutions US, Ray Carnes
on 2/19/13, 3:07 PM

order will be AND [OR A B] OR C OR D E -> AND [OR A B] OR C [OR D E] -> AND [OR A B] [OR C [OR D E]] so yes it gives the same result.

Altınkaya Elektronik Cihaz Kutuları imalat Ticaret ltd sti, Ahmet Altinisik
on 2/19/13, 3:59 PM

Thanks. Both answers helped me formulate the process I outlined in my answer.

Bista Solutions US, Ray Carnes
on 2/19/13, 4:00 PM

Ray Carnes

--Ray Carnes--
| 9 7 9
Atlanta, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0; Odoo 8.0, 9.0, 10.0.

Completed Odoo Functional and Technical Training.

Major Skills:

  • User Needs and GAP Analysis;

  • Functional and Technical Design;

  • Prototyping and Proof of Concepts;

  • Requirements Specifications;

  • Agile Implementation;

  • Data Migration;

  • Configuration & Customization (UI and code);

  • Integration - Odoo and non Odoo Applications and Services;

  • Training and Knowledge Transfer;

  • Go Live Support;

  • Helpdesk;

  • Version Upgrades and Migration.

  • Accounting Expert.

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. 

I am a skilled Communicator and I only take the serious things seriously!

Ray Carnes
On 2/19/13, 3:29 PM

My method for simplification:

(1) Start with the outermost operator and move it to the start of the expression.

"(A operator B)"  becomes  "operator (A B)"

(2) Repeat step 1 for each sub expression with an operator to move.

"A operator (B operator C)"  becomes  "operator A (B operator C)"  then "operator A (operator B C)"

(3) Remove all brackets.

"A operator (B operator C)"  becomes  "operator A operator B C"

So for my example:

( A or B ) AND ( C or D or E )

First simplification:

AND ( A or B ) ( C or D or E )

left side

AND ( or A B ) ( C or D or E )

right side outer

AND ( or A B ) ( or C ( D or E ) )

right side inner

AND ( or A B ) ( or C ( or D E ) )

remove brackets

AND or A B or C or D E

In OpenERP domain syntax this would be:

[ '&', 'I', (A), (B), '|', (C), '|', (D), (E) ]
Pablo Manuel Rizzo
On 2/18/13, 6:10 PM

Your first guess is OK. You may find easyer to understan it if you start with the Reversed Polish Notation, which is a little more intuitive for programmers.


There is a good example:

The infix expression "5 + ((1 + 2) * 4) − 3" can be written down like this in RPN:

5 1 2 + 4 * + 3 -

The reversed notation is exactly the same, but enables you to resolve without going back and forth.

The infix expression requires you to compute first the inner addition "1 + 2", then multiply by 4, then add 5 and finally add 3, off course you can change some orders and thats one problem.

With reverse polish notation you apply the operators you find to the inmediately preceding operands in the stack, the partial result replace them as a new operand, you follow the same with the next operator, an so on until there's no more operators. In this case: "5 1 2 + 4 * + 3 -" you find + and apply to 1 and 2, replace with the partial result, now your stack is "5 3 4 * + 3 -", find first operator again, *, and apply to two preceding operands, 4 and 3, now you have this stack "5 12 + 3 -", find the next operator, + , and apply to preceding operands, 5 and 12, replace the result in the stack "17 3 -", again, find the firs operator and apply the preceding operands: "14". Done.

In this example you take always two operands because thats that's what apply to the operators, if you find unary operator (a negation for example) you apply to only one preceding operand. You could find an operator which requires 3 or more operands.

In your example, if you reverse and simplify the expression you get this:

E D C | | B A | &

If you resolv this logical expresion with the same algorithm follow in the previous numeric example, you'll find you get exactly what you want.

Thereafter, you only need to acomodate your mind to the non-reversed notation, which is the same, perhaps a little bit less intuitive.

Hope this helps.

Best regards.

Thanks. All this makes sense apart from the 'reverse and simplify the expression'! That's the part I was a foolproof method for. I get AND OR A B OR C OR D E as I comment above when I do it. If that's right then I think I have a method.

Bista Solutions US, Ray Carnes
on 2/19/13, 3:09 PM

Pablo can we write Domain filters also in reverse polish notation or did you give this since it is easier to understand ? Do we need to reverse the reverse polish notation to use in domain filters?

Altınkaya Elektronik Cihaz Kutuları imalat Ticaret ltd sti, Ahmet Altinisik
on 2/20/13, 4:24 AM

OpenERP uses direct Polish Notation, not reversed. I use reverse notation to explain the method because I personally find the reverse notation a little bit more intuitive, but that's not necesary true for everybody, and I think Ray found a very clean way to explain the direct Polish Notation.

Naltu, Pablo Manuel Rizzo
on 2/20/13, 9:48 AM

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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/18/13, 3:29 PM
Seen: 24163 times
Last updated: 8/24/16, 3:48 PM