how-to-inherit-and-customize-an-existing-pdf-report-in-odoo

How to Inherit and Customize an Existing PDF Report in Odoo?

Why Existing PDF Report in Odoo Matters for Your Business

In Odoo, many modules come with built-in PDF reports, like Quotations, Invoices, and Purchase Orders. Sometimes, your business requirements need a slight adjustment: you may want to add a field, change the layout, or include a digital signature. Instead of rewriting the entire report, you can inherit the existing QWeb report and extend or override specific parts.

In this blog, you’ll learn how to inherit an existing PDF report in Odoo 18 and customize it effectively using best practices.

Functional Goal

Let’s say you want to add the Customer VAT Number to the existing Invoice PDF.

Step 1: Identify the Original Report

Every report in Odoo has a report_name and is registered in XML. For customer invoices, the default report is:

				
					


Purchase Order
purchase.order
qweb-html
my_module.report_purchase_order
my_module.report_purchase_order

report





				
			

So we know the QWeb template to inherit is: account.report_invoice.

Step 2: Create an Inherited QWeb Template

Use xpath to inject or override elements in the base QWeb template.

				
					

 <!-- Add Customer VAT Number under the Customer Address -->

<div>
<strong>Customer VAT:</strong> <span />
 </div>




				
			

Explanation:

  • inherit_id tells Odoo which template you’re modifying.
  • xpath points to the element in the original template.
  • position=”after” means insert your code right after that element.

Step 3: Package Your Customization

You can include the template above in any custom module. For example, if your module is custom_invoice_report, place it in:

				
					custom_invoice_report/views/report_invoice_inherit.xml
In your __manifest__.py, add:
'depends': ['account'],
'data': [
'views/report_invoice_inherit.xml',
],

				
			

Step 4: Restart and Upgrade Your Module

Run the following commands:

				
					# Restart Odoo server
./odoo-bin -u custom_invoice_report -d your_db_name

				
			

Now go to Invoices > Print > Invoice, and you’ll see your new field.

Optional: Override an Entire Section

If you need deeper changes, you can override a whole block. Example:

				
					
  <div class="invoice_address">
    <!-- your custom HTML block -->
  </div>

				
			

Best Practices for Customizing PDF Reports

To ensure your customizations are efficient and maintainable, follow these best practices:

Use xpath Selectors Wisely

  • Be specific with your xpath expressions to avoid affecting unintended elements.
  • Test your xpath thoroughly to ensure it works across all report variations.

Leverage Odoo Debug Mode

Activate debug mode to inspect and easily identify elements in the original QWeb template.

Avoid Directly Editing Core Files

Always inherit and extend templates rather than modify core files to ensure compatibility with future updates.

Keep Code DRY

Avoid duplicating entire templates; override only the necessary sections to reduce redundancy.

Document Changes

Add comments in your XML to explain the purpose of your customizations for future reference.

Test Thoroughly

Print sample reports to verify that your changes render correctly in various scenarios.

Version Control

Use version control (e.g., Git) to track and manage changes in your custom module.

Keep Your Odoo Reports Smart and Scalable

Customizing existing PDF reports in Odoo is clean and maintainable via QWeb inheritance. This method allows you to:

  • Identify the report template.
  • Create an inherited XML view.
  • Modify specific sections using xpath.
  • Package and deploy the customization in a custom module.

This approach avoids duplicating entire templates and keeps your code DRY and future-proof.

By following the most promising practices mentioned above, you can ensure that your customizations remain robust, efficient, and upgrade-friendly.

Picture of Ashna George

Ashna George

I am Ashna George, a Python and Odoo Developer specializing in developing and customizing Odoo modules. I focus on building efficient, user-friendly ERP solutions using Python, XML, and QWeb.

Get a free quote