Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I don´t understand Normal Polish Notation (NPN or PN). How to build a complex domain in Odoo?

Could someone translate the following polish notation to its SQL counterpart:

['|', '&', ('is_company','=', True),('parent_id', '=', False),('company_name', '!=', False),('company_name', '!=', '')]

My guess is :

is_company = True OR parent_id = False AND company_name <> False AND company_name <> ''

I could not get the concept of this notation no matter how hard I tried to understand it. Please help.

UPDATE

I was trying to extend the above notation to be:

((is_company = True AND parent_id = False) OR company_name <> False) AND company_name <> '' AND customer_type_id <> False

like image 843
Lekhnath Avatar asked Jan 30 '18 13:01

Lekhnath


People also ask

What is Polish notation write the steps required to perform Polish notation?

Polish notation is a notation form for expressing arithmetic, logic and algebraic equations. Its most basic distinguishing feature is that operators are placed on the left of their operands. If the operator has a defined fixed number of operands, the syntax does not require brackets or parenthesis to lessen ambiguity.

Why do computers use reverse Polish notation?

Reverse Polish Notation (RPN) was devised as a method of simplifying mathematical expressions. RPN predates modern computers. It became useful with the advent of electronic calculators that were not great at handling complex expressions that needed brackets.

Why is reverse Polish notation RPN used to carry out the evaluation of expressions?

Reverse Polish notation (RPN) is a method for conveying mathematical expressions without the use of separators such as brackets and parentheses. In this notation, the operators follow their operands, hence removing the need for brackets to define evaluation priority.

How do you interpret Reverse Polish Notation?

In reverse Polish notation, the operators follow their operands; for instance, to add 3 and 4 together, one would write 3 4 + rather than 3 + 4.


1 Answers

I totally agree with you, each time I have to do a complex domain using this kind of Polish notation, I have to rack my brains to manage it.

I think the domain you're looking for is:

['&amp;', '|', '&amp;', ('is_company', '=', True), ('parent_id', '=', False), ('company_name', '!=', False), '&amp;', ('company_name', '!=', ''), ('customer_type_id', '!=', False)]

I made up a method to get these complex domains, and it's working:

First I write a letter instead of each condition:

A => is_company = True => ('is_company', '=', True)
B => parent_id = False => ('parent_id', '=', False)
C => company_name <> False => ('company_name', '!=', False)
D => company_name <> '' => ('company_name', '!=', '')
E => customer_type_id <> False => ('customer_type_id', '!=', False)

Then build the expression you need using only the letters and the standard operators, forget about the Polish notation and the conditions:

Step 0. => ((A and B) or C) and D and E

Afterwards, group the operations you should execute the first (don't mind about the missing operators so far):

Step 1. => ((A and B) or C) and D and E
Step 2. => (AB or C) and D and E
Step 3. => ABC and D and E
Step 4. => ABC and DE

Now we have only an operator, let's start decomposing it again (and moving the operator to the left of each couple of conditions), following the reverse order in which you grouped the operations (for example, from step 3 to 4 you grouped DE, so now, from step 4 to 3, decompose DE and move its operator to its left):

Step 4. => and ABC DE
Step 3. => and ABC and D E
Step 2. => and or AB C and D E
Step 1. => and or and A B C and D E

Now change the operators and add the commas, the quotes and the brackets:

['&amp;', '|', '&amp;', A, B, C, '&amp;', D, E]

Finally, replace the letters with the conditions, and there you have your domain. It would be better to explain it face to face but may be you were able to understand everything.

Note: I don't remove the &amp; operators (despite if you don't write them, Odoo should take them by default) because my experience is that with largest domains, if I didn't write the &amp;, the domain didn't work. I guess this happened when there was a lot of nested conditions, but my advice is to write always them.

like image 85
forvas Avatar answered Sep 28 '22 08:09

forvas