Common Structure
View objects 提供了一系列的字段接口,除非特殊指明,否則這些字段都是可選的。
name
(必選)
用以描述這個View,通常是爲了在一堆list中找到它,主要是爲了可讀性。
model
它指明這個view相關的model
priority
客戶端可以通過指明 id
或 (model, type)
的形式來調用 view。 如果是後面這種情況,所以對應 model 的 type 正確的 view 都會被搜索出來,並返回這些 view 中 priority 最低的哪一個 (it is the ‘default view’)。priority
也在 view inheritance 時,設置了 order
arch
the description of the view’s layout
groups_id
指明允許哪些組來訪問或使用當前 view
inherit_id
指明當前 view 的 parent view
mode
如果這個 view 沒有設置 inherit_id 字段,那麼 mode
的值就只能是 primary
,如果設置了 inherit_id 字段,那麼默認的,mode
的值被設置爲 extension
,但是,也可以強制設置其值爲 primary
。
application
website feature defining togglable views. By default, views are always applied
Inheritance
View matching
- 如果某個 view 被
(model, type)
的方式被請求調用,將會返回對應 model 的對應 type 的 view, 這個 view 必須是mode=primary
並且 lowest priority 。 - 當某個 view 被
id
指明調用,如果這個 view 的 mode 不是 primary,將返回它最近的 parent view 且 parent view 的mode=primary
View resolution
通過對 matched primary
view 的解析,生成最後的 arch
- 首先,如果這個 view 有 parnet,parent view 將會被完整的解析,並且當前 view 對 parent view 修改的部分也將被處理。
- 其次,如果這個 view 沒有 parent, 那麼這個 view 中設置的 arch 就是 arch
- 最後,如果這個 view 有 children,那麼所有的 children 都將被找出來,並按照 depth-firth 的順序依次處理他們對 parent view 繼承部分的修改。
通過這三個步驟,生成最終的arch
Inheritance specs
三種繼承寫法:
- 設置一個包含
expr
屬性的xpath
tag。expr
就是普通的XPath
表達式,作用於arch
,返回第一個符合要求的節點。 - 設置一個包含
name
屬性的field
tag。返回name
相同的field
- 其他的 tag, 但是第一個屬性是
name
,且其他屬性完全一樣(除了position
屬性)
可以通過添加 postition
屬性,來實現對 matched node的修改:
inside
(default) 作爲 matched node 的最後一個孩子節點插入
replace
替換掉整個 matched node
after
在 matched node 後面添加,作爲其兄弟節點
before
插在 matched node 之前
attributes
是如果是這種情況,那麼這個content 應該爲一系列 <attribute>
且有 name
屬性,以及這個 <attribute>
可選的 body。
- 如果
<attribute>
有 body,那麼 matched node 就會被設置一個屬性爲 attribute 中的 name的值,這個屬性爲 attribute的 body - 如果
<attribute>
沒有body, 那麼 matched node 對應名字爲name的值
的屬性,將會被刪除。如果 matched node 沒有name 的值
的屬性,就將會拋出異常
view spec 將會被順序的執行。
Lists
list views 的跟節點就是 <tree>
,list views 的跟節點可以設置以下屬性:
editable
沒默認情況下,當你點擊 list view 中的某一行時,將會打開這一行對應 record 的 form view 中。而通過設置 editable
屬性,將使得 list view 可以被就地更改,而不用去對應的form view去修改。
這個屬性的值可以被設置爲 top
或者 bottom
,這將是新增的 record 出現的位置。
inline form view 是從 list view 派生出來的,所以 form view 中的 fields 和 button的大部分屬性都可以被 list view所接收,但是如果list view不是 editable的話,這些屬性也通常不會起作用。
default_order
覆蓋這個 view 對應model 的 order。 值爲 逗號分割的字段名的組合,如果在後面添加 desc
表示 reverse
<tree default_order="sequence,name,id desc">
colors
- 9.0 時,被廢棄,改爲 decoration-{$name}
fonts
- 9.0 被廢棄, 改爲 decoration-{$name}
decoration-{$name}
允許根據 record 的某些屬性,來修改這行 record 的 text style
這個屬性的值爲一個 python 表達式,他將依次作用與當前顯示的每一個 record,用每一個 record的屬性來作爲這個表達式的context,來運算。如果這個表達式爲 true,那麼對應的樣式就將會作用與這一行上。同時,這個 context 除了 record的屬性,還由Odoo 提供uid
(當前登錄用戶的 id)和 current_date
(當前日期被 strftime yyyy-MM-dd
的字符串)
{$name}
可以是 bf
(font-weight: bold
), it
( font-style: italic
), 或者任意 bootstrap contextual color (danger
,info
,muted
,primary
,success
,warning
).
create
, edit
, delete
通過設置這些屬性爲 false
,可以使的對應的操作被隱藏。
on_write
僅僅在 editable list 中生效。值應該爲這個 list 對應的 model 的某個 method的 name。在創建或者修改某個 record之後,這個method 將會被調用,同時這個record 的 id
也將會被傳入這個 method中。
這個 method 應該返回 a list of ids of other records to load or update。
string
可選,用來翻譯。8.0 廢棄
這個 root tag 的 children 通常有:
button
在 list cell 中顯示一個 button
icon
用來顯示這個 buttonstring
- 如果沒有設置
icon
, 那麼這個就是 button 的 text - 如果設置了
icon
,那麼這個就是 button 的alt
text
- 如果沒有設置
type
button 的類型,用以表明當點擊這個button時,odoo採取何種行爲workflow
(default)
傳遞一個型號給 workflow,button 的name
就是 workflow的 signal。同時這一行對應的 record 將會被作爲一個參數傳遞給 workflowobject
調用這個list對應 model 的某個方法,button 的name
就是方法的名字,傳入當前 record id 和 contextaction
調用ir.actions
的某個action。button 的name
就是這個 action 的 database id。同時 context 中將會包含這個 list 對應的 model (active_model
),當前行對應的 record(active_id
),已經當前頁面中所有 loaded 的 record(active_ids
, 可能是經過篩選之後的 sub recordset)。
name
seetype
args
seetype
attrs
基於當前 record value 的動態屬性
一系列 attribute 和 domain 組成的 dict。domain 在當前 context 環境下作用於對應 record,如果 true, cell 就被設置這個 attribute。
通常 attribute 是invisible
和readonly
。states
就是attrs
中對invisible
的快捷方式。用逗號分割的state 選項 組成的字符串。這個list 對應的 model 中必需設置了state
字段。而且state
字段在 這個 view 中設置了。如果當前 state 不在列出的裏面,就隱藏這個 buttoncontext
點擊button,將會 merge 到這個 view 的 context 中。然後傳入後方confirm
調用某個方法之前,彈出一個對話框,用以用戶確認。
field
指明哪些 field 將會被 column 的形式被展現出來。屬性有:
name
這個model 的字段的名字。在同一個field name 在同一個 view 中只能出現一次。string
這個 field 的標題, 沒設置的話,就用 model 對應字段的 stringinvisible
獲取這個字段的值,但是不顯示出來。通常是因爲在某些其他字段中需要使用到這個字段,比如說在<tree>
的decoration-{$name}
的表達式 中。groups
設置哪些組可以看到這個字段widget
改變某些字段的顯示方式progressbar
將float
field 用 progressbar 的型式展現many2onebutton
將一個many2one
field 的值替換成某個符號,如果這個field 有值就是某個icon,handle
, 就是作用於sequence
這個字段,將這個字段的值從數字變成一個表示可以拖曳的 icon
sum
,avg
在底部顯示相關字段的和或者平均值。通常要通過group_operator
來顯示。<field name="planned_revenue" sum="Expected Revenues"/> <field name="probability" avg="Avg. of Probability"/>
Note:
如果 list view 是editable
的,那麼 form view 中的任意 field attribute 都可以作用於 inline form view 上。