Enable Dark Mode!
how-to-inherit-existing-pivot-view-report-in-odoo-19.jpg
By: Sonu S

How To Inherit Existing Pivot View Report in Odoo 19

Technical Odoo 19 Odoo Enterprises Odoo Community

The goal of the all-inclusive business management platform Odoo 19 is to enhance user experience, automation, and efficiency. Along with bolstering security and compliance, it improves critical areas like sales, accounting, inventory, CRM, HR, and eCommerce. It accommodates companies of all sizes with deployment options spanning Odoo Online, Odoo.sh, and on-premise servers. The solution facilitates smooth integrations through REST API and is based on Python and PostgreSQL with OWL for frontend development. The Pivot Report is a noteworthy feature that aids companies in dynamic data analysis, filtering, and producing structured reports for improved decision-making. Odoo 19 provides a scalable and affordable ERP solution with both a feature-rich Enterprise edition and a free Community edition.

Odoo 19's Pivot view is a sophisticated reporting feature that facilitates effective analysis and interpretation of massive amounts of data. Businesses can use drill-down functionality to explore data, create thorough reports for deeper insights, and organize information using custom categories. Across several categories, including sales, inventory, and finance, users can apply filters, rearrange data, and monitor important KPIs. The Pivot view is a useful tool for corporate intelligence and well-informed decision-making since it also allows data export.

Adding Custom Fields to the Sale Report

For instance, by inheriting and expanding the Sale Report Pivot view, we may improve it. The pivot view's basic structure is shown below; we can alter it to include other fields.

How To Inherit Existing Pivot View Report in Odoo 19-cybrosys

The Sales Report in Odoo provides important information about sales performance. To enhance their reporting capabilities, companies could want more fields. We can solve this by adding custom fields to the current sale.report model, making sure they are appropriately organized for precise data analysis, and integrating them into queries.

Python:

from odoo import fields, models
class SaleReport(models.Model):
    """Extended version of Sale Report with extra computed metrics."""
    _inherit = "sale.report"
    # Example additional fields
    order_display_name = fields.Char(string="Order Display Name")
    invoice_progress = fields.Selection([
        ('no', 'Not Yet Invoiced'),
        ('to invoice', 'Pending Invoice'),
        ('invoiced', 'Completely Invoiced')
    ], string="Invoice Progress")
    customer_reference = fields.Char(string="Customer PO Reference")
    # New analytical measures
    total_items = fields.Integer(string="Total Items", group_operator="sum")
    total_weight = fields.Float(string="Total Weight", group_operator="sum")
    def _select_additional_fields(self):
        """Adding custom SQL fields into the Sale Report query."""
        result = super()._select_additional_fields()
        result.update({
            "order_display_name": "s.name",
            "invoice_progress": "s.invoice_status",
            "customer_reference": "s.client_order_ref",
            "total_items": "SUM(l.product_uom_qty)",
            "total_weight": "SUM(l.product_uom_qty * p.weight)",
        })
        return result
    def _group_by_sale(self):
        """Ensure SQL grouping includes the new fields."""
        group_by = super()._group_by_sale()
        group_by += """, s.name, s.invoice_status, s.client_order_ref"""
        return group_by

Two essential methods are overridden in order to enable the recently added fields in the Sale Report:

_select_additional_fields() - This approach applies the required aggregations and expands the selection query to cover more fields.

_group_by_sale() - By using this technique, query failures are prevented and the new fields are correctly categorized when data is fetched.

Creating an XML View to Extend the Pivot Report

We must inherit the current pivot view xml and add our custom fields to the report view in order to make the recently added fields accessible in the Sale Report Pivot view.

xml

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <!-- Inherit Pivot View -->
    <record id="view_sale_report_pivot_inherit_custom" model="ir.ui.view">
        <field name="name">sale.report.pivot.inherit.custom</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="before">
                <!-- Add New Measures -->
                <field name="total_items" type="measure"/>
                <field name="total_weight" type="measure"/>
                <!-- Add New Fields -->
                <field name="order_display_name"/>
                <field name="invoice_progress"/>
                <field name="customer_reference"/>
            </xpath>
        </field>
    </record>
    <!-- Inherit Search View -->
    <record id="view_sale_report_search_inherit_custom" model="ir.ui.view">
        <field name="name">sale.report.search.inherit.custom</field>
        <field name="model">sale.report</field>
        <field name="inherit_id" ref="sale.view_order_product_search"/>
        <field name="arch" type="xml">
            <xpath expr="//search/group[filter[@name='User']]" position="inside">
                <filter name="order_display_name" string="Order Display Name" context="{'group_by':'order_display_name'}"/>
                <filter name="invoice_progress" string="Invoice Progress" context="{'group_by':'invoice_progress'}"/>
                <filter name="customer_reference" string="Customer Reference" context="{'group_by':'customer_reference'}"/>
            </xpath>
        </field>
    </record>
</odoo>

Inherited Report View

The following outcomes may be seen following the installation of this customized module with the expanded Sale Report model and pivot view modifications:

How To Inherit Existing Pivot View Report in Odoo 19-cybrosys

The recently added fields - Order Display Name, Invoice Progress, and Customer Reference are shown in the image above. These improvements allow us to conduct in-depth data analysis. For instance, by placing Order Display Name on the horizontal axis (Columns) and Invoice Progress on the vertical axis (Rows), we can examine sales data in the Pivot View. As seen in the picture below, this configuration enables us to see how sales orders are distributed among various invoice stages for every customer, which facilitates trend identification and pending invoice tracking.

How To Inherit Existing Pivot View Report in Odoo 19-cybrosys

Furthermore, as illustrated in the figure below, we may access the recently added measurements, including Total Items and Total Weight, by selecting the measurements option. This makes it possible to examine sales performance using these important metrics in greater detail.

How To Inherit Existing Pivot View Report in Odoo 19-cybrosys

The outcome of choosing those measures is depicted in the following figure:

How To Inherit Existing Pivot View Report in Odoo 19-cybrosys

Businesses can improve their Pivot View reports by adding more fields and computations by customizing the sale.report model in Odoo 19. Businesses can make well-informed decisions based on pertinent data thanks to this customization, which offers more thorough insights into sales performance.

In addition to sale.report, other Odoo reports such as purchase.report, account.invoice.report, and stock.report can also be extended using this method. By altering these reports, companies can customize their analytics to meet certain operational requirements while maintaining easy access to important data. These improvements allow users to arrange records according to different criteria, filter data, and display additional computed values by using the Measures button.

All things considered, modifying Pivot View reports in Odoo facilitates better decision-making, increases visibility into corporate processes, and enables a more organized and insightful examination of crucial data.

To read more about How to Inherit an Existing Pivot View Report in Odoo 18, refer to our blog How to Inherit an Existing Pivot View Report in Odoo 18


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