Graph views provide a graphical view of the data, in the form of a chart. The current fields available in the To-do Tasks are not good candidates for a chart, so we will add one to use on such a view.
In the TodoTask
class, at the todo_ui/models/todo_model.py
file, add:
effort_estimate = fields.Integer('Effort Estimate')
It also needs to be added to the To-do Task form, so that we can add values for it on the existing records, and are able to check this new view.
Now let's add the To-Do Tasks graph view:
<record id="view_graph_todo_task" model="ir.ui.view"> <field name="model">todo.task</field> <field name="arch" type="xml"> <graph type="bar"> <field name="stage_id" /> <field name="effort_estimate" type="measure" /> </graph> </field> </record>
The graph
view element can have a type
attribute that can be set to bar
(the default), pie
, or line
. In the case of bar
, the additional stacked="True"
can be used to make it a stacked bar chart.
The data can also be seen in a pivot table, a dynamic analysis matrix. For this, we have the pivot view, introduced in version 9.0. Pivot tables were already available in version 8.0, but in 9.0, they moved into their own view type. Along with this, it improved the UI features of Pivot tables, and optimized the retrieval of pivot table data greatly.
To also add a pivot table to the To-Do Tasks, use this code:
<record id="view_pivot_todo_task" model="ir.ui.view"> <field name="arch" type="xml"> <pivot> <field name="stage_id" type="col" /> <field name="user_id" /> <field name="date_deadline" interval="week" /> <field name="effort_estimate" type="measure" /> </pivot> </field> </record>
The graph and pivot views should contain field elements describing the axis and measures to use. Most of the available attributes are common to both the view types:
name
identifies the field to use in the graph, just like in other viewstype
is how the field will be used, as a row
group (default), a measure
, or as col
(only for pivot tables, use for column groups)interval
is meaningful for date fields, and is the time interval used to group time data by day
, week
, month
, quarter
, or year
By default, the aggregation used is the sum of the values. This can be changed by setting the group_operator
attribute on the Python field definition. The values that can be used include avg
, max
, and min
.