Odoo 16 Development Book

Pivot view

A Pivot table view is the best tool to calculate and also analyze data. In Odoo, we can create pivot tables for our model so that users get a table structure of all the records.

Let us see how to set the pivot table.

First, we have to create a model, menu, and menu action.

from odoo import models, fields
class ExampleOdoo(models.Model):
    _name="example.odoo"
    example_field = fields.Char(string="Example Field")
    example_field1 = fields.Many2one('res.users', 'User', required=True)
<record id="action_Example" model="ir.actions.act_window">
                        <field name="name">Example</field>
                        <field name="type">ir.actions.act_window</field>
                        <field name="res_model">example.odoo</field>
                        <field name="view_mode">form,tree,pivot</field>
                    </record>
                    <menuitem id="example_menu"
                            name="Example Odoo"
                            action="action_Example"/>

Then create the pivot view like this.

<record id="example_pivot_view" model="ir.ui.view">
                                <field name="name">example.pivot</field>
                                <field name="model">example.odoo</field>
                                <field name="arch" type="xml">
                                    <pivot string="Project Tasks">
                                        <field name="example_field" type="row"/>
                                        <field name="example_field1" type="col"/>
                                    </pivot>
                                </field>
                            </record>

The output will be

odoo Development
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message