Enable Dark Mode!
how-to-create-a-pdf-report-in-odoo-17.jpg
By: Pranav TV

How to Create a PDF Report in Odoo 17?

Technical Odoo 17

Odoo is a powerful open-source ERP and business management software that offers a wide range of features to streamline various aspects of your business operations. One of the essential components of any business management software is reporting, and Odoo excels in this area with its PDF report generation capabilities. In this blog post, we'll explore how Odoo 17 simplifies the process of creating and customizing PDF reports to meet your specific business needs.

Odoo 17 introduces several improvements and features to enhance the generation of PDF reports. Whether you need financial statements, sales invoices, purchase orders, or any other document, Odoo's reporting capabilities allow you to create professional and customizable PDF reports effortlessly.

What is Qweb?

Qweb is the templating engine of choice in Odoo, enabling users to transform XML data into HTML documents with ease. Its attribute-based properties, conditional statements, dynamic content capabilities, and support for report templates make it a versatile tool for creating customized and visually appealing reports, emails, and other documents. Whether you need to generate financial statements, invoices, or complex business reports, Qweb simplifies the process and ensures that your output is both informative and aesthetically pleasing.

Let's create a custom PDF report in Odoo 17 for the "product.template" model. This process involves creating a QWeb template and a corresponding report action. Both of these records should be placed inside the "report" directory of your module's structure. Here's a step-by-step guide:

Module Structure:

how-to-create-a-pdf-report-in-odoo-17-1-cybrosys

Create the Report Action (XML file):

Inside your module's "report" directory, create an XML file for the report action. Let's name it ir_actions_report.xml. This file will define the report action that binds the report to the model. Below is an example of what the XML file might contain:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
   <record id="action_report_product_template" model="ir.actions.report">
       <field name="name">Product Report</field>
       <field name="model">product.template</field>
       <field name="report_type">qweb-pdf</field>
       <field name="report_name">custom_report.report_product</field>
       <field name="report_file">custom_report.report_product</field>
       <field name="print_report_name">'Product Report - %s' % (object.name)</field>
       <field name="binding_model_id" ref="product.model_product_template"/>
       <field name="binding_type">report</field>
   </record>
</odoo>

In this XML file, we define a report action with a name, a model it's associated with (in this case, "product.template"), the report type as "qweb-pdf," and the report name. The report_name field should point to the QWeb template that we'll create in the next step.

The report action defined earlier will result in the addition of a new report option under the "Print" menu within the related model, which in this case is "product.template." This custom report will be seamlessly integrated into the "Print" menu, making it easily accessible for users. The user interface will reflect the following changes, as illustrated below:

how-to-create-a-pdf-report-in-odoo-17-2-cybrosys

Create the QWeb Template (XML file):

Now, create another XML file for the QWeb template. Name it product_report.xml. This file will define the structure and content of your custom PDF report. Here's a simplified example:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
   <template id="report_product">
       <t t-call="web.html_container">
           <t t-foreach="docs" t-as="o">
               <t t-call="web.external_layout">
                   <div class="page">
                       <div class="oe_structure"/>
                       <h2>Product Report</h2>
                       <br></br>
                       <p>
                         Name :  <span t-field="o.name"/>
                       </p>
                   </div>
               </t>
           </t>
       </t>
   </template>
</odoo>

In the QWeb template XML file, we define a template with the same name referenced in the report action's report_name field. Inside the template, we use t-foreach to loop through the product records (docs) and generate content for each product. You can include HTML and QWeb expressions to format and display the information as required.

The given template will print the PDF Report given below.

how-to-create-a-pdf-report-in-odoo-17-3-cybrosys

Don’t forget to add both XML files inside the Manifest file.

To read more about creating a custom Pdf report in Odoo 16, refer to our blog How to Create a Custom PDF Report in Odoo 16


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

London

Cybrosys Limited
Alpha House,
100 Borough High Street, London,
SE1 1LB, United Kingdom

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