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
393 views
in Technique[技术] by (71.8m points)

odoo - Understanding OpenERP Domain Filter?

I would like to ask you if you could please explain the anatomy of the Openerp domain filters. I have to use it 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 meaning of (order_id.user_id','=',user.id), what is order_id, user_id, and user.id. Are they referencing any table. If yes then how am I supposed to know which one...

Basically I want to know decipher the notation from bottom up so that can use it as per my requirement.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

This one is pretty simple.

Consider the following fields (only XML i've given here, python you got to manage)

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

Single Condition

Consider some simple conditions in programming

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

In Open ERP domain filter it would be written this way

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

So the syntax we derive is

('field_name', 'operator', value)

Now let's try to apply another field in place of static value 5

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

In the above you've to note that first variable a is enclosed with single quotes whereas the value b is not. The variable to be compared will be always first and will be enclosed with single quotes and the value will be just the field name. But if you want to compare variable a with the value 'b' you've to do the below

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

Condition AND

In Programming

if a = 5 and b = 10

In Open ERP domain filter

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

Note that if you don't specify any condition at the beginning and condition will be applied. If you want to replace static values you can simply remove the 5 and give the field name (strictly without quotes)

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

Condition OR

In Programming

if a = 5 or b = 10

In Open ERP domain filter

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

Note that the , indicates that it's and condition. If you want to replace fields you can simply remove the 5 and give the field name (strictly without quotes)

Multiple Conditions

In Programming

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

In Open ERP domain filter

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

Also this post from Arya will be greatly helpful to you. Cheers!!


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

1.4m articles

1.4m replys

5 comments

57.0k users

...