Enable Dark Mode!
how-to-inherit-existing-pivot-view-report-in-odoo-17.jpg
By: Ayana KP

How to Inherit Existing Pivot View Report in Odoo 17

Technical Odoo 17

In Odoo, pivot view reports provide valuable insights into business data by summarizing and presenting it in a pivot table format. However, there are times when businesses need to customize these reports to meet their specific requirements. Inheriting existing pivot view reports allows users to extend the functionality of standard reports without starting from scratch.

In this blog post, we will explore how to inherit existing pivot view reports in Odoo 17.

Understanding Pivot View Reports:

Before delving into inheritance, let's briefly understand what pivot view reports are. In Odoo, pivot view reports are used to analyze large datasets by organizing them into rows and columns, with the ability to perform various operations such as grouping, filtering, and aggregation. These reports provide a dynamic way to visualize data and gain actionable insights.

Steps to Inherit Existing Pivot View Reports in Odoo 17:

1. Inheriting Model:

To illustrate view inheritance, let's examine a sales report. Below is a screenshot displaying a Sales Analysis report.

how-to-inherit-existing-pivot-view-report-in-odoo-17-1-cybrosys

Here is the Python code demonstrating how to inherit a sales report  in Odoo 17:

from odoo import models, fields, api
class SaleReport(models.Model):
    _inherit = 'sale.report'
    # Add custom fields or override existing ones if needed
    custom_field = fields.Char(string='Custom Field')

2. Inheriting View:

In the provided screenshot, the sales team is arranged in columns, while the dates are organized in rows. Now, let's reverse these fields: display dates in columns and sales teams in rows. To accomplish this, we will inherit the Sales report view.

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_order_product_pivot_inherit" model="ir.ui.view">
   <field name="name">sale.report.pivot.inherit</field>
   <field name="model">sale.report</field>
   <field name="inherit_id" ref="sale.view_order_product_pivot"/>
   <field name="arch" type="xml">
   <xpath expr="//field[@name='team_id']" position="replace">
       <field name="team_id" type="row"/>
   </xpath>
   <xpath expr="//field[@name='date']" position="replace">
       <field name="date" interval="month" type="col"/>
   </xpath>
   </field>
</record>
</odoo>

In the provided code snippet, we utilize the external ID 'sale.view_order_product_pivot' to inherit the existing pivot report. Here, we replace and configure the fields, setting the date field to be displayed as columns and the team_id field as rows.

The subsequent screenshot showcases the resulting output of the sales analysis report post-inheritance.

how-to-inherit-existing-pivot-view-report-in-odoo-17-2-cybrosys

3. To Add More Fields as Rows or Columns:

To include additional fields as rows or columns, let's explore an example:

Example: Define the following code in an XML file.

<record id="view_order_product_pivot_inherit" model="ir.ui.view">
<field name="name">sale.report.pivot.inherit</field>
<field name="model">sale.report</field>
<field name="inherit_id" ref="sale.view_order_product_pivot"/>
<field name="arch" type="xml">   
<xpath expr="//field[@name='team_id']" position="after">
<field name="company_id" type="col"/>
</xpath>
</field>
</record>

In the provided code snippet, we've incorporated the "company" field as a column. Upon implementation of the above code, this field will manifest as a subfield (expanded field) under the date field.

how-to-inherit-existing-pivot-view-report-in-odoo-17-3-cybrosys

To substitute the default field in the pivot view, you can employ the following command:

<xpath expr="//field[@name='team_id']" position="replace">
    <field name="company_id" type="col"/>
</xpath>

Inheriting existing pivot view reports in Odoo 17 provides a powerful mechanism for customizing and extending standard reports to meet specific business needs. By following the steps outlined in this blog post, users can leverage the flexibility of Odoo's framework to enhance the functionality of pivot view reports and gain deeper insights into their data.

To read more about how we inherit existing pivot view reports in Odoo 16, refer to our blog How Can We Inherit Existing Pivot View Reports in Odoo 16


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 


whatsapp_icon
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