Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
508 views
in Technique[技术] by (71.8m points)

python - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...