How to Inherit and Customize an Existing Pivot View Report in Odoo 17

blog-banner

Odoo 17 comes with powerful reporting features, and the Pivot view stands out as a particularly effective tool for analyzing and summarizing large amounts of data. It allows users to dynamically rearrange and filter data to generate insightful reports, making it an essential feature for business analytics. However, the default Pivot view may not always meet the specific needs of your business. In such cases, inheriting and customizing the existing Pivot view is the perfect solution.

In this blog post, we will walk you through the process of inheriting and customizing an existing Pivot view report in Odoo 17.

Steps to Add a New Field in the Pivot View

Let's take an example where we want to add a custom field, check_in_mode, to the attendance report's Pivot view. This can be done by following these steps:

1. Inherit the Model and Add a New Field

First, you need to inherit the existing model (hr.attendance) and add your custom field. Below is the Python code demonstrating how to inherit the attendance model and add a new field:

    <!-- Python -->
            from odoo import models, fields  
     
            class HrAttendance(models.Model):  
                _inherit = 'hr.attendance'  
     
                # Add custom field for check-in mode 
                check_in_mode = fields.Selection( 
                    selection=[('kiosk', "Kiosk"),  
                               ('systray', "Systray"),  
                               ('manual', "Manual")],  
                    string="Check In Mode",  
                    default='manual' 
                ) 
    

2. Inherit the Pivot View and Add the Custom Field

Next, you need to inherit the existing Pivot view and add the custom field check_in_mode to the view. Here’s how you can do it using XML:

  <?xml version="1.0" encoding="utf-8" ?>  
    <odoo>  
    <record id="hr_attendance_view_pivot_inherit" model="ir.ui.view">  
    <field name="name">hr.attendance_view_pivot.inherit</field>  
    <field name="model">hr.attendance</field>  
    <field name="inherit_id" ref="hr_attendance.hr_attendance_view_pivot"/>  
    <field name="arch" type="xml">  
    <xpath expr="//field[@name='check_in']" position="after">  
    <field name="check_in_mode" type="col"/>  
    </xpath>  
    </field>  
    </record>  
    </odoo>
    

By this now you can see your custom field in pivot view

Custom Field Added in Pivot View
 

Adding Custom Filters and Groupings to the Pivot View

In addition to adding custom fields, enhancing your Pivot view with custom filters and groupings can significantly improve the analytical capabilities of your reports. Custom filters allow users to focus on specific subsets of data, while custom groupings help in categorizing data for better insights. Below, we’ll add custom filters and groupings to the Pivot view.

1. Adding Custom Filters

Custom filters allow users to refine the data displayed in the Pivot view based on specific criteria. To add a custom filter, you need to modify the search view associated with the model.

Here's an example of how to add a filter based on the check_in_mode field that we previously added:

   <record id="view_hr_attendance_filter" model="ir.ui.view"> 
    <field name="name">hr.attendance.filter</field> 
    <field name="model">hr.attendance</field> 
    <field name="inherit_id" ref="hr_attendance.hr_attendance_view_filter"/> 
    <field name="arch" type="xml"> 
    <xpath expr="//filter[@name='check_in_filter']" position="after"> 
    <filter string="Check In Mode" name="filter_check_in_mode" domain="[('check_in_mode', '=', 'manual')]"/> 
    </xpath> 
    </field> 
    </record>
    

This filter will appear in the search options of the Pivot view, allowing users to easily filter the attendance records based on the check-in mode.

Add Customer Filter View in Odoo 17 Pivot View Report

2. Adding Custom Groupings

Groupings in the Pivot view allow data to be categorized and aggregated based on specific fields. To add a custom grouping based on the check_in_mode field, you need to modify the Pivot view:

With this setup, the attendance data will be grouped by check_in_mode in the Pivot view, allowing users to see how many check-ins were done via Kiosk, Systray, or Manual methods, and compare the results across different dimensions.

   <record id="view_hr_attendance_filter" model="ir.ui.view"> 
    <field name="name">hr.attendance.filter</field> 
    <field name="model">hr.attendance</field> 
    <field name="inherit_id" ref="hr_attendance.hr_attendance_view_filter"/> 
    <field name="arch" type="xml"> 
    <xpath expr="//filter[@name='groupby_name']" position="after"> 
    <filter string="Check In Mode" name="groupby_check_in_mode" context="{'group_by': 'check_in_mode'}"/> 
    </xpath> 
    </field> 
    </record>
    

Add Custom Groupings in Pivot View Report

Conclusion

Inheriting and customizing Pivot views in Odoo 17, as part of comprehensive Odoo Development Services, enables you to tailor reporting tools to precisely match your business requirements. By following the steps in this guide, you can enhance default reports to provide greater value to your end users. Customizing the Pivot view ensures that your business has access to the exact data needed for effective decision-making, empowering your team with insights tailored to drive success.

Contact us

For Your Business Requirements

Text to Identify Refresh CAPTCHA
Background Image Close Button

2 - 4 October 2024

Hall: 10, Booth: #B8 Brussels, Belgium