Understanding the OpenERP Domain Filter?

I would like to ask you if you can explain the reason for the anatomy of Openerp domain filters. I have to use it in my project. Please explain the description of the following domain filter.

['|',('order_id.user_id','=',user.id),('order_id.user_id','=',False)] 

I want to know the exact value (order_id.user_id','=',user.id) , which is order_id , user_id and user.id They refer to any table. If so, how should I know which one ...

Basically, I want to know, to decrypt the notation from bottom to top, so that I can use it in accordance with my requirement.

+7
odoo
source share
2 answers

It is pretty simple.

Consider the following fields (only the XML provided here, python that you must manage)

 <field name="a"/> <field name="b"/> <field name="c"/> 

Only condition

Consider some simple programming conditions.

 if a = 5 # where a is the variable and 5 is the value 

In the Open ERP domain filter window, it will be written this way

 [('a','=',5)] # where a should be a field in the model and 5 will be the value 

So we get the syntax

 ('field_name', 'operator', value) 

Now try applying a different field instead of a static value of 5

 [('a','=',b)] # where a and b should be the fields in the model 

In the above, you should notice that the first variable a is enclosed in single quotes , while the value of b is not . The variable to be compared will always be the first and will be enclosed in single quotes, and the value will simply be the name of the field. But if you want to compare the variable a with the value "b", you should do below

 [('a','=','b')] # where only a is the field name and b is the value (field b value will not be taken for comparison in this case) 

Condition AND

In programming

 if a = 5 and b = 10 

In the "Open ERP Domain Filter" window

 [('a','=',5),('b','=',10)] 

Please note that if you do not specify any condition at the beginning, the condition and will be applied. If you want to replace static values, you can simply remove 5 and specify the field name ( strictly without quotes )

 [('a','=',c),('b','=',c)] 

Condition OR

In programming

 if a = 5 or b = 10 

In the "Open ERP Domain Filter" window

 ['|',('a','=',5),('b','=',10)] 

Please note that , indicates that this condition and . If you want to replace the fields, you can simply delete 5 and specify the field name ( strictly without quotes )

Several conditions

In programming

 if a = 5 or (b != 10 and c = 12) 

In the "Open ERP Domain Filter" window

 ['|',('a','=',5),('&',('b','!=',10),('c','=',12))] 

Also this post from Arya will be very useful for you. Hooray!!

+20
source share

"|" this is OR, which applies to the next comparison. (..., '=', False) is converted to IS NULL, so SQL for this will be

 WHERE order_id.user_id = x OR order_id.user_id is NULL 

The default value is AND, so you do not see ('&', ('field1', '=', 1), ('field2', '=', 2) everywhere.

Note that another useful one ('field1', '! =', False) that converts to the WHERE1 field is not NULL

There is not a lot of documentation for this, and they are rather complicated with several operators, since you have to work through tuples in the reverse consumption of operators. I find that I use complex infrequently so much that I just turn on logging in Postgres and use the trial version and error, watching the generated requests until I get it right.

+3
source share

All Articles