Hello Odooers,
Let me share how to create a Pivot View in Odoo 18, a powerful reporting tool that allows you to analyze data with dynamic grouping, filtering, and aggregation. It's widely used for sales analysis, inventory reports, HR dashboards, and more.
What is a Pivot View in Odoo?
A Pivot View in Odoo is an innovative and powerful reporting tool that enables you to analyze and compare large amounts of data quickly. It works like Excel's pivot tables but directly inside Odoo. You can group data by rows and columns, check totals, averages, or counts, and even drill down for more details. With Pivot View, you get a clear picture of sales, expenses, inventory, or any other business data, all organized in an interactive table that's easy to use.
In this blog, we'll walk you through the step-by-step process of creating a Pivot View in Odoo 18. By the end, you'll not only know how to set it up but also how to use it effectively for reporting and analysis.
Step 1: Create Your Model
Define a model with fields for dimensions (such as date, user, and partner) and measures (such as totals and counts).
.py
from odoo import models, fields
class DevSaleReport(models.Model):
_name = "dev.sale.report"
_description = "Sales Report Demo"
date = fields.Date(string="Order Date", index=True)
user_id = fields.Many2one("res.users", string="Salesperson")
partner_id = fields.Many2one("res.partner", string="Customer")
total_amount = fields.Float(string="Total Amount")
order_count = fields.Integer(string="Order Count", default=1)
Step 2: Add Pivot View XML
Use the <pivot> tag and specify rows, columns, and measures.
.py
from odoo import models, fields,api
@api.depends('sport_fees', 'library_fees')
def compute_total_fees(self):
for total in self:
abc=total.sport_fees + total.library_fees
total.fees=abc
name = fields.Char(string='Student Name')
fees = fields.Float(string='Total fees', compute='compute_total_fees')
Step 3: Add Action & Menu
Make sure view_mode includes pivot.
XML
<record id="action_dev_sale_report" model="ir.actions.act_window">
<field name="name">Sales Analysis</field>
<field name="res_model">dev.sale.report</field>
<field name="view_mode">pivot,tree,form</field>
</record>
<menuitem id="menu_dev_reports" name="Dev Reports"/>
<menuitem id="menu_dev_sale_report" name="Sales Analysis"
parent="menu_dev_reports" action="action_dev_sale_report"/>
odoo pivot view: create best Practices
- Use stored fields for grouping (e.g., store=True on computed fields).
- Add index=True to frequently grouped fields (such as dates, user, and partner).
- Keep pivot queries light with default filters (e.g., last 12 months).
- Use interval=" month|year" for time-based grouping.
With this setup, you'll have a fully functional Pivot View in Odoo 18, ready to deliver interactive reports for your users.
Looking for more Odoo 18 tutorials? Explore our Devintelle Odoo technical blogs to level up your development skills.