### 圖像視圖
圖的視圖允許匯總匯總和分析模型,它們的根元素是 `<graph>`.
圖形視圖有4個顯示模式,使用的默認模式是使用 `@type` 屬性.
Pivot
多維表,允許各種尺寸的選擇得到合適的聚合數據集之前,移動到一個更圖形概述
Bar (默認)
一個條形圖,第一維是用來定義在水平軸上的組,其他維度定義在每個組中的聚集的酒吧。
默認的酒吧是并排的,他們可以堆疊使用 `@stacked="True"` 在 `<graph>` 上
Line
二維直線圖
Pie
2維的餅圖
圖視圖包含 `<field>` 具有強制性 `@type` 屬性取值:
`row` (默認)
該字段應為默認聚合
`measure`
該領域應匯總,而不是分組
~~~ xml
<graph string="Total idea score by Inventor">
<field name="inventor_id"/>
<field name="score" type="measure"/>
</graph>
~~~
Warning
圖形視圖對數據庫執行的聚合值,他們不與非存儲計算字段。
練習
圖像視圖
在每一個過程中,在一個條形圖的形式下,為每一個過程,顯示的次數增加一個圖形視圖。
1. 添加作為存儲計算字段的參與者數量
2. 然后添加相關視圖
*openacademy/models.py*
~~~ python
hours = fields.Float(string="Duration in hours",
compute='_get_hours', inverse='_set_hours')
attendees_count = fields.Integer(
string="Attendees count", compute='_get_attendees_count', store=True)
@api.depends('seats', 'attendee_ids')
def _taken_seats(self):
for r in self:
~~~
~~~ python
for r in self:
r.duration = r.hours / 24
@api.depends('attendee_ids')
def _get_attendees_count(self):
for r in self:
r.attendees_count = len(r.attendee_ids)
@api.constrains('instructor_id', 'attendee_ids')
def _check_instructor_not_in_attendees(self):
for r in self:
~~~
*openacademy/views/openacademy.xml*
~~~ xml
</field>
</record>
<record model="ir.ui.view" id="openacademy_session_graph_view">
<field name="name">openacademy.session.graph</field>
<field name="model">openacademy.session</field>
<field name="arch" type="xml">
<graph string="Participations by Courses">
<field name="course_id"/>
<field name="attendees_count" type="measure"/>
</graph>
</field>
</record>
<record model="ir.actions.act_window" id="session_list_action">
<field name="name">Sessions</field>
<field name="res_model">openacademy.session</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,gantt,graph</field>
</record>
<menuitem id="session_menu" name="Sessions"
~~~