Other types of views

The most frequent view types used are the form and list views, discussed until now. Other than these, a few other view types are available, and we will give a brief overview on each of them. Kanban views won't be addressed now, since we will cover them in Chapter 8, QWeb – Creating Kanban Views and Reports.

Remember that the view types available are defined in the view_mode attribute of the corresponding window action.

Calendar views

As the name suggests, this view presents the records in a calendar. A calendar view for the to-do tasks could look like this:

<record id="view_calendar_todo_task" model="ir.ui.view">
  <field name="name">view_calendar_todo_task</field>
  <field name="model">todo.task</field>
  <field name="arch" type="xml">
    <calendar date_start="date_deadline" color="user_id"
              display="[name], Stage [stage_id]">
      <!-- Fields used for the text of display attribute -->
      <field name="name" />
      <field name="stage_id" />
    </calendar>
  </field>
</record>

The calendar attributes are these:

  • date_start: This is the field for the start date (mandatory).
  • date_end: This is the field for the end date (optional).
  • date_delay: This is the field with the duration in days. This is to be used instead of date_end.
  • color: This is the field used to color the calendar entries. Each value in the field will be assigned a color, and all its entries will have the same color.
  • display: This is the text to be displayed in the calendar entries. Fields can be inserted using [<field>]. These fields must be declared inside the calendar element.

Gantt views

This view presents the data in a Gantt chart, which is useful for scheduling. The to-do tasks only have a date field for the deadline, but we can use it to have a basic Gantt view working:

<record id="view_gantt_todo_task" model="ir.ui.view">
  <field name="name">view_gantt_todo_task</field>
  <field name="model">todo.task</field>
  <field name="arch" type="xml">
    <gantt date_start="date_deadline"
           default_group_by="user_id" />
  </field>
</record>

Attributes that can be used for Gantt views are as follows:

  • date_start: This is the field for the start date (mandatory).
  • date_stop: This is the field for the end date. It can be replaced by the date_delay.
  • date_delay: This is the field with the duration in days. It can be used instead of date_stop.
  • progress: This is the field that provides completion percentage (between 0 and 100).
  • default_group_by: This is the field used to group the Gantt tasks.

Graph views

The graph view type provides a data analysis of the data, in the form of a chart or an interactive pivot table.

We will add a pivot table to the to-do tasks. First, we need a field to be aggregated. In the TodoTask class, in the todo_ui/todo_model.py file, add this line:

    effort_estimate = fields.Integer('Effort Estimate')

This should also be added to the to-do task form so that we can set some data on it. Now, let's add the graph view with a pivot table:

<record id="view_graph_todo_task" model="ir.ui.view">
  <field name="name">view_graph_todo_task</field>
  <field name="model">todo.task</field>
  <field name="arch" type="xml">
    <graph type="pivot">
      <field name="stage" type="col" />
      <field name="user_id" />
      <field name="date_deadline" interval="week" />
      <field name="effort_estimate" type="measure" />
    </graph>
  </field>
</record>

The graph element has a type attribute set to pivot. It can also be bar (default), pie, or line. In the case of bar, an additional stacked="True" can be used to make it a stacked bar chart.

The graph should contain fields that have these possible attributes:

  • name: This identifies the field to use in the graph, as in other views.
  • type: This describes how the field will be used, as a row group (default), as a col group (column), or as a measure.
  • interval: only meaningful for date fields, this is the time interval used to group time data by day, week, month, quarter or year.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset