How to Customize Existing Reports in Odoo 18

Arsalan Yasin

Odoo 18 features a powerful reporting system that enables businesses to generate detailed, insightful reports tailored to their unique needs. However, default reports may not always address specific business requirements, making customization necessary. In this blog, we’ll guide you through customizing reports in Odoo 18, helping you align them more closely with your business processes.

Steps to Customize Existing Reports in Odoo 18

1. Understanding Odoo Reports Odoo reports are built using QWeb, Odoo's XML-based templating engine, combined with Python and the Odoo framework. These reports play a crucial role in analyzing data from various modules. Before diving into customization, it's essential to understand the key components of these reports:

  • Models: Define the underlying data structure and business logic.
  • Views: Specify how the data is presented to users.
  • QWeb Templates: Handle the layout and design of the report output.

2. Locating Existing Reports To customize an existing report, you first need to identify its location within Odoo. This can be done in the Technical section under Settings, where you'll find the report templates and their associated details. This section allows you to access template names and the underlying code for modification.

3. Inheriting and Modifying Reports

Customizing a report in Odoo involves inheriting it within your custom module. Follow these steps to modify an existing report:

  • Create a New XML File: Add the file to your module’s views directory.
  • Inherit the Report Template: Use the <template> tag to inherit the existing report template and implement your changes.

For example, to include a customer code field in the res.partner model, your code would look like this:

class ResPartner(models.Model): 
"""Extending res.partner to add customer code for all partners"""
 _inherit = 'res.partner' 
customer_code = fields.Char(string='Customer ID', help='Unique identification number for partners')

Next, to include this field in all invoice PDF reports, inherit the invoice template:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Inheriting the invoice PDF template to add customer code -->
    <template id="report_invoice_document" inherit_id="account.report_invoice_document">
        <xpath expr="//div[@name='address_same_as_shipping']//t[@t-set='address']" position="inside">
            <div t-if="o.partner_id.customer_code">
                Customer ID: <span t-out="o.partner_id.customer_code"/>
            </div>
        </xpath>
        <xpath expr="//div[@name='address_not_same_as_shipping']//t[@t-set='address']" position="inside">
            <div t-if="o.partner_id.customer_code">
                Customer ID: <span t-out="o.partner_id.customer_code"/>
            </div>
        </xpath>
        <xpath expr="//div[@name='no_shipping']//t[@t-set='address']" position="inside">
            <div t-if="o.partner_id.customer_code">
                Customer ID: <span t-out="o.partner_id.customer_code"/>
            </div>
        </xpath>
    </template>
</odoo>

In this example, the invoice PDF template is modified to display the customer code in the address section. Using XPath expressions allows for precise placement of elements, ensuring the customer code appears correctly based on the address setup.

Customizing reports in Odoo 18 allows you to tailor the system to your unique business requirements. By following the steps provided, you can create a custom module, inherit existing reports, and make dynamic adjustments using Python. With careful planning and testing, you can improve your reports and gain deeper insights into your business operations.