Enable Dark Mode!
inheriting-existing-pdf-reports-in-odoo14.jpg
By: Hajaj Roshan

Inheriting Existing PDF Reports in Odoo14

Technical Odoo 14

New reports in Odoo can be crafted based on our needs of operations. Moreover, occasionally we need to make certain changes to the existing report and this is also possible here. The alteration inside the existing qweb reports is possible with the help of inheriting the existing qweb report.

In this blog, we will be discussing the aspects of Inheriting and existing PDF reports in Odoo 14.

Creating a new module

The Initial step is to create a new module and it's always better to inherit in Odoo, and not to modify existing files. You can create a new module by using the following code:

Tip: use the scaffold command from Odoo!

inheriting-existing-pdf-reports-in-odoo14-14

In case you need to add to the existing qweb reports, you should inherit the qweb report template and further then add the contents to the existing report for that initially you have to find the External ID (or XML ID). For inheriting a report initially, you have to know which module it is being described and what the original XML ID of the report is. 

The external ID of a defined qweb report is always in the format “module_name.template”. In the aspects of inheriting an existing report, finding the external ID falls as the priority task and is the most difficult one, for that initially you have to find the report. So, how do you find this? Initially go to the Settings-->Technical-->Reports, find the existing report, and further then you have to select on the qweb views.

inheriting-existing-pdf-reports-in-odoo14-14

Check for the correct view and choose it or else you can directly go to the Settings-->Technical-->Views, and find out the view of the existing report where the ‘External ID’ field will be described. The external ID of the existing report will be defined as depicted in the following screenshot.

inheriting-existing-pdf-reports-in-odoo14-14

Let's now move onto the inheritance aspects of the existing report which can be done by creating an XML file.

Create an XML file

First, we want to create a new module, then create an XML file in it (XML file name.xml). Then inherit the existing report as follows,

<?xml version="1.0" encoding="utf-8"?>	
 <odoo>
 <data> 
<template id="sales_report"  inherit_id="sale.report_saleorder_document">
<xpathexpr="//div[hasclass('class_name')]" position="after/before/replace">
   //here we can add the changes 
</xpath>
</template>
 </data>
 </odoo>

As the inheriting aspect of the report is completed let's now move on to obtaining an inheritance ID to the report.

Create a template with an id and give inherit_id as the External ID of it

The provision of inherite ID is also done in the above code where I have created a template with ID as sales_report and inherite_id as the external ID of the sales order reported “sale.report_saleorder_document”. Then use ‘xpath expr’ to specify the correct position that you want to modify, after that specify the ‘position’ then download the sale report PDF and see the changes on that report.

Finally, ensure that you have added the module name in which the original report exists as the dependency of the newly created module and add the new XML file in the data section of the module manifest. Then install the module and print the report, you can see the modification will reflect in your existing report.


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



0
Comments



Leave a comment

 


whatsapp
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