تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
20417 أدوات العرض

I want to 'AND', 'OR' condition in single search. 

docids = self.env['sale.product.list'].search([ (('branch_id', '=', a_market_id) '&' ('deli_user_id', '=', a_deli_user_id) '&' ('user_id', '=', a_user_id)) '|' (('branch_id', '=', a_market_id) '&' ('deli_user_id', '=', a_deli_user_id) ) ])
الصورة الرمزية
إهمال

By default 'search' function takes 'AND' condition between 2 args. You can add 'OR' / 'AND' via '|' / '&' signs.

in faOtools' answer, I don't understand why he says its "Reverse Polish Notation, where the operators follow their operands", but then he goes on to show operands following the operators.  Am I misunderstanding?



I believe it's actually just "Polish Notation" and not "Reverse Polish Notation" -- can anyone confirm? This point has been confusing me :)

أفضل إجابة

Odoo domain is a typical Reverse Polish Notation representative, where operators follow their operands. Look at this wikipedia article for the detailed explanation.

So, '&' and '|' should be before the conditions. '&' might be not set explicitly.

  • ["&", A, B] > both A and B should be satisfied. The same as [A, B]

  • ["|", A, B] > either A or B should be True

  • ["&", A, "|", B, C] > A should be True AND (either B or C should be True)

  • ["|", A, "&", B, C] > Either A should be True OR  (both B & C should be True)

Have a look also at the similar Odoo question - https://www.odoo.com/es_ES/forum/ayuda-1/question/domain-notation-using-multiple-and-nested-and-2170 

الصورة الرمزية
إهمال

How about this one sir? "['|', '|', '&', A, B, C, D, E]"
I can't understand this domain.

أفضل إجابة

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 Odoo domain syntax this would be:

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

الصورة الرمزية
إهمال
أفضل إجابة

One fairly easy way to get familiar with the notation is to create user-defined filters through the standard Odoo front-end, and you can see what Odoo generates for various combinations of operators and conditions.  

https://odootricks.tips/domain-in-odoo/ 

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يوليو 25
1151
Search a message تم الحل
1
فبراير 25
1625
0
سبتمبر 23
2595
2
يونيو 23
4633
1
أغسطس 22
13321