OpenERP7.0中Domin條件表達式寫法總結
1) Domin條件表達式規則
最簡單的格式:
[('字段
', '操作符
', 值
)]
例:
[('shenqr.user_id', '=', uid)]
說明:
domain中的單個條件是一個三個元素組成的元組,所以務必加上()。
元組中第一個是對象的一個column,也就是字段名;
元組中第二個是比較運算符 “=, !=, >, >=, <, <=, like, ilike, in, not in,
child_of, parent_left, parent_right“ ;(注意:在xml文件中使用時,'>='要
用'>='表示 ,'<='要用 '<='表示,'!='最好用'><'表示,'>'最好
用'>'表示,'<'最好用 '<' 表示)
元組中第三個就是用來比較的值了。
多個條件用“|”(or),“&”(and),“!”(no)邏輯運算符鏈接。
邏輯運算符作爲前綴放置於條件前面。“|”與“&”必須兩個條件鏈接,“!”對一個條件取反。
默認邏輯運算符爲“&”。(注意:在xml文件中使用時,'&'要用'&'表示)
2) 不帶邏輯運算符的簡單表達式
過濾狀態爲待批: [('state', '=', 'wait_prove')]
過濾狀態爲草稿、待批:
[('state', 'in', ('draft', 'wait_prove'))] 或者 [('state', 'in', ['draft', 'wait_prove'])]
過濾請假天數大於3天: [('tians', '>', 3)]
3) 帶邏輯運算符的簡單表達式
假設a , b分別是不帶邏輯運算符的簡單表達式
a = ('state','><','draft')
b = ('tians', '<=', 1)
a and b: [ a, b ] 或 [ '&' , a , b ]
a or b: [ '|', a,b ]
Eg:
請假模塊,副經理登錄時待審批的請假單(狀態是待批,並且請假天數在一天以內)菜單過濾條件:
<field name="domain">[('state','=','wait_prove'),('tians', '<=', 1)]</field>
4) 帶邏輯運算符的稍複雜的表達式
同上,假設a , b, c分別是不帶邏輯運算符的簡單表達式
a and b and c : [a, b, c] 或則 [ '&', '&', a, b, c]
a or b or c: ['|', '|', a , b , c]
a and b or c: ['|', '&', a, b, c]
a and (b or c): ['&', a, '|', b, c]
Eg:
經理待審批的請假單(狀態是待批,並且請假天數大於一天,並且是本部門的職員請假單,並且還不包含自己的請假單)菜單過濾條件
<field name="domain"> [('state', '=', 'wait_prove'), ('tians', '>', 1), ('shenqr.user_id','<>',uid),('shenqr.department_id','=',department_id),('shenqr.user_id.groups_id', '=', 59)] </field>
5) 帶邏輯運算符的更復雜的表達式
同上,假設a , b, c, e, f, g分別是不帶邏輯運算符的簡單表達式
(a or b and c) or ( d and e ) :
['|', '&','|', a, b, c, '&', d, e, 3)]
Eg:
總經理待審批的請假單(所有部門副經理或經理狀態爲待批的請假單,或3天以上部門經理批准過的請假單)菜單過濾條件:
<field name="domain">['|', '&','|', ('shenqr.user_id.groups_id', '=', 60), ('shenqr.user_id.groups_id', '=', 61), ('state', '=', 'wait_prove'), '&', ('state','=','depmanager_proved'),('tians', '>', 3)]</field>
(a or b and c) or (d and e) or (f and g)
['|','|', '&','|', a, b, c, '&', d,e,'&', f,g]
Eg:
總經理全部的請假單(所有部門副經理或經理狀態爲待批的請假單,或3天以上部門經理批准過的請假單,或3天以上狀態爲同意或駁回的請假單據)菜單過濾條件:
<field name="domain">['|','|', '&','|', ('shenqr.user_id.groups_id', '=', 60), ('shenqr.user_id.groups_id', '=', 61), ('state', '=', 'wait_prove'), '&', ('state','=','depmanager_proved'),('tians', '>', 3),'&', ('state','in',['proved','rejected']),('tians', '>', 3)]</field>
5) 參考資料
http://www.cnblogs.com/cnshen/p/3189306.html
http://shine-it.net/index.php?topic=5864.0
6) 注意和7.0之前的版本差異較大:
v6.0的部分寫法如下圖:
原文:http://blog.csdn.net/littlebo01/article/details/17509761