A Pivot table view is the most effective tool for calculating and analysing data. We can create pivot tables in Odoo for our model so that users can see a table structure of all the records.
Let's look at how to configure the pivot table.
We must first create a model, menu, and menu action.
from odoo import fields, models
class VisaApplication(models.Model):
_name = "visa.application"
name = fields.Char(string="Name", help="Name of the applicant")
age = fields.Integer(string="Age", help="Age of the applicant")
gender = fields.Char(string="Gender", help="Gender of the applicant")
date_of_birth = fields.Date(string="Date of Birth", help="Date of birth")
<record id="record_action" model="ir.actions.act_window">
<field name="name">Visa Application</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">visa.application</field>
<field name="view_mode">tree,form,pivot</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a new record!
</p>
</field>
</record>
<menuitem id="parent_menu_root"
name="Visa"
sequence="6"/>
<menuitem id="menu_id"
name="Visa Application"
parent="parent_menu_root"
action="record_action"
sequence="10"/>
The pivot view is then created as shown.
<record id="visa_application_pivot" model="ir.ui.view">
<field name="name">visa.application.pivot</field>
<field name="model">visa.application</field>
<field name="arch" type="xml">
<pivot string="Project Tasks">
<field name="name" type="row"/>
<field name="age" type="col"/>
</pivot>
</field>
</record>
The result will be