« Back

Graph and Pivot in Odoo 10

Odoo provides a facility to represent data in a graphical and tabular format. There are two types of data representation in odoo.

Graph views: The graph view gives a way to look at your data and to visualize it in various ways. A graph is a another mode of view same as form and tree and it provides a graphical view of the data, in the form of a chart.

  • Types of graph:
    • Line chart
    • Bar chart
    • Pie chart

Pivot table: The basic use of pivot table is that you can select the desired dimensions, use the search bar to select appropriate filters, and switch to various chart modes.

You can re-organize and summarize selected columns and rows of data in a spreadsheet or database table to obtain a desired report. A pivot table doesn't actually change the spreadsheet or database itself. Its root element is <pivot>.

Bellow are the attributes used in graph and pivot views:

Attributes:

  • type: It indicates whether the field should be used as a grouping criteria or as an aggregated value within a group. Possible values are:
    • row (default): Groups by the specified field. All graph types support at least one level of grouping, some may support more. For pivot views, each group gets its own row.
    • col: Only used by pivot tables, creates column-wise groups
    • measure: Field to aggregate within a group. Every field of type integer or float (except the id field) can be used as a measure.
  • name (required): The name of a field to use in a graph view. If used for grouping rather than aggregating.
  • interval: It is used for date and datetime fields, groups by the specified interval (day, week, month, quarter or year).

    For example,

    • date_field:day,
    • date_field:week,
    • date_field:month (default)
    • date_field:quarter,
    • date_field:year

  • Stacked: If present and set to True, stacks bars within a group. (Only used for bar charts)
  • disable_linking: Set to True to remove table cell's links to list view. (Only used by pivot tables)
  • display_quantity: Set to true to display the Quantity column by default. (Only used by pivot tables)
  • group_operator: It is used to do sum or average operation for specific field. You have to define it in .py file as per below example.

'price_total': fields.float('Total Price', readonly=True, group_operator = 'avg')

Here, I am going to explain the graph and pivot views with examples.

1. Line chart or line graph is a type of chart which displays information as a series of data points connected by straight line segments. It is a basic type of chart common in many fields.

Following xml code is for creating line graph.

<record id="view_stock_level_forecast_graph" model="ir.ui.view">

       <field name="name">Stock.forecast.graph</field>

       <field name="model">report.stock.forecast</field>

       <field name="arch" type="xml">

           <graph string="Stock Level forecast" type="line">

               <field name="product_id" type="col"/>

               <field name="cumulative_quantity" type="measure"/>

           </graph>

       </field>

</record>

 

2. Bar chart is a diagram in which the numerical values of variables are represented by the height or length of lines or rectangles of equal width.

<record id="view_project_task_graph" model="ir.ui.view">

   <field name="name">project.task.graph</field>

   <field name="model">project.task</field>

   <field name="arch" type="xml">

       <graph string="Project Tasks" type="bar" stacked="True">

           <field name="project_id" type="row"/>

           <field name="planned_hours" type="measure"/>

       </graph>

   </field>

 

3. Pie chart is a type of graph in which a circle is divided into sectors that each represent a proportion of the whole.

<record model="ir.ui.view" id="view_stock_quant_graph_value">

       <field name="name">stock.quant.graph</field>

       <field name="model">stock.quant</field>

       <field eval="12" name="priority"/>

       <field name="arch" type="xml">

           <graph string="Inventory Valuation" type="pie">

               <field name="product_id" type="row"/>

               <field name="qty" type="measure"/>

               <field name="inventory_value" type="measure"/>

           </graph>

       </field>

</record>

 

4. Pivot table is a multidimensional table that you can configure to display any possible cube for your data.

<record id="view_sale_history_report_pivot" model="ir.ui.view">

        <field name="name">sale.order.pivot</field>

        <field name="model">sale.report</field>

        <field name="arch" type="xml">

            <pivot string="Sales History Analysis">

               <field name="partner_id" type="row"/>

               <field name="order_id" type="row"/>

               <field name="price_total" type="measure"/>

               <field name="date:day" type="row"/>

               <field name="name" type="col"/>

               <field name="product_id" type="col"/>

            </pivot>

        </field>

</record>

Comments
No comments yet. Be the first.

Contact Us

For your business requirements

Loading

Get in touch

Headquarter : 302, Landmark, Nr. Titanium City Center, Prahlad Nagar Road, Ahmedabad, India - 380015.

Showing 1 - 5 of 20 results.
of 4
contact-us Request a callback