How to Create a PDF Report in Odoo
18
Enterprise
Enterprise
In Odoo 18, creating a PDF report involves defining a report
template using QWeb, linking it to a model, and customizing its
structure. The process includes setting up an XML report
definition, designing the layout with a QWeb template, and
integrating it into your module. This allows you to generate
detailed, printable reports (e.g., invoices, sale orders) directly from
the Odoo interface.
Introduction
Enterprise
QWeb is Odoo's templating engine, used to convert XML data into
HTML with ease. It supports dynamic content, conditional
statements, and customizable templates, making it ideal for
creating reports, emails, and documents. Whether for invoices,
financial statements, or business reports, QWeb ensures outputs
are clear and visually appealing.
What is Qweb?
Enterprise
Enterprise
First, we need to define the structure. For this, we'll use an
example by creating a new module named custom_report. Inside
this module, create a folder called report and add two files:
ir_actions_report.xml and product_report.xml, then specify the
necessary code in them.
Explanation
Enterprise
In your module's "report" folder, create an XML file named
ir_actions_report.xml. This file will define the report action that
links the report to the model. Here's an example of what the XML
file could include:
Create the Report Action (XML file)
Enterprise
Report Action (XML file)
<?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>
Enterprise
1. XML Declaration: Specifies the XML format and character
encoding.
2. Root Element: Defines <odoo> as the root element for Odoo
XML files.
3. Report Record: Creates a report action with a unique ID
(action_report_product_template).
4. Report Name: Names the report as "Product Report" for
display in the UI.
5. Model: Links the report to the product.template model.
Explanation(code)
Enterprise
● Report Type: Specifies the report format as QWeb PDF.
● QWeb Template Name: Points to the QWeb template
(custom_report.report_product).
● Template File Name: Specifies the QWeb template file for rendering the report.
● Dynamic Report Name: Sets a dynamic name using the product's name (e.g.,
"Product Report - [Name]").
● Binding to Model: Binds the report to the product.template model using its
reference.
● Binding Type: Marks the report as available in the "Print" menu for the model.
● Closing Tags: Ends the <record> and <odoo> elements properly.
Explanation(code)
Enterprise
This XML file defines a report action with a name, an associated
model (product.template), the report type (qweb-pdf), and a link
to the QWeb template we’ll create next.
Once added, this report will appear as a new option under the
"Print" menu in the product.template model.
Report(print product report)
Enterprise
Enterprise
Next, create an XML file named product_report.xml. This file will
define the layout and content of your custom PDF report. Here's
a simple example:
Create the QWeb Template (XML file)
Enterprise
Code
<?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>
Enterprise
● XML Declaration: Declares the XML version and encoding.
● Root Element: Defines the root element <odoo> for Odoo XML files.
● Template Definition: Creates a QWeb template with the ID report_product.
● HTML Container: Calls Odoo's default HTML container for consistent layout.
● Loop Through Records: Iterates over records (docs) to generate the report for each.
● External Layout: Applies Odoo's default external layout (e.g., header, footer).
● Page Content: Defines the report’s content, such as the product name (o.name).
Explanation(code)
Enterprise
● Define a template in the QWeb XML with the same name as the
report_name field in the report action.
● Use t-foreach to loop through the product records and generate
content for each one.
● Apply HTML and QWeb expressions to format and display the
information.
Explanation(workflow)
Enterprise
The Template Will Generate the
PDF Report Below
Enterprise
It shows how to create a custom PDF report in Odoo 18 using
QWeb templates. By defining the report action and template,
you can easily generate and print reports directly from Odoo.
This makes it simple to add custom reports to your system.
Conclusion
For More Info.
Check our company website for related blogs
and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
Enterprise
www.cybrosys.com

How to Create a PDF Report in Odoo 18 - Odoo Slides

  • 1.
    How to Createa PDF Report in Odoo 18 Enterprise
  • 2.
    Enterprise In Odoo 18,creating a PDF report involves defining a report template using QWeb, linking it to a model, and customizing its structure. The process includes setting up an XML report definition, designing the layout with a QWeb template, and integrating it into your module. This allows you to generate detailed, printable reports (e.g., invoices, sale orders) directly from the Odoo interface. Introduction
  • 3.
    Enterprise QWeb is Odoo'stemplating engine, used to convert XML data into HTML with ease. It supports dynamic content, conditional statements, and customizable templates, making it ideal for creating reports, emails, and documents. Whether for invoices, financial statements, or business reports, QWeb ensures outputs are clear and visually appealing. What is Qweb?
  • 4.
  • 5.
    Enterprise First, we needto define the structure. For this, we'll use an example by creating a new module named custom_report. Inside this module, create a folder called report and add two files: ir_actions_report.xml and product_report.xml, then specify the necessary code in them. Explanation
  • 6.
    Enterprise In your module's"report" folder, create an XML file named ir_actions_report.xml. This file will define the report action that links the report to the model. Here's an example of what the XML file could include: Create the Report Action (XML file)
  • 7.
    Enterprise Report Action (XMLfile) <?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>
  • 8.
    Enterprise 1. XML Declaration:Specifies the XML format and character encoding. 2. Root Element: Defines <odoo> as the root element for Odoo XML files. 3. Report Record: Creates a report action with a unique ID (action_report_product_template). 4. Report Name: Names the report as "Product Report" for display in the UI. 5. Model: Links the report to the product.template model. Explanation(code)
  • 9.
    Enterprise ● Report Type:Specifies the report format as QWeb PDF. ● QWeb Template Name: Points to the QWeb template (custom_report.report_product). ● Template File Name: Specifies the QWeb template file for rendering the report. ● Dynamic Report Name: Sets a dynamic name using the product's name (e.g., "Product Report - [Name]"). ● Binding to Model: Binds the report to the product.template model using its reference. ● Binding Type: Marks the report as available in the "Print" menu for the model. ● Closing Tags: Ends the <record> and <odoo> elements properly. Explanation(code)
  • 10.
    Enterprise This XML filedefines a report action with a name, an associated model (product.template), the report type (qweb-pdf), and a link to the QWeb template we’ll create next. Once added, this report will appear as a new option under the "Print" menu in the product.template model. Report(print product report)
  • 11.
  • 12.
    Enterprise Next, create anXML file named product_report.xml. This file will define the layout and content of your custom PDF report. Here's a simple example: Create the QWeb Template (XML file)
  • 13.
    Enterprise Code <?xml version="1.0" encoding="utf-8"?> <odoo> <templateid="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>
  • 14.
    Enterprise ● XML Declaration:Declares the XML version and encoding. ● Root Element: Defines the root element <odoo> for Odoo XML files. ● Template Definition: Creates a QWeb template with the ID report_product. ● HTML Container: Calls Odoo's default HTML container for consistent layout. ● Loop Through Records: Iterates over records (docs) to generate the report for each. ● External Layout: Applies Odoo's default external layout (e.g., header, footer). ● Page Content: Defines the report’s content, such as the product name (o.name). Explanation(code)
  • 15.
    Enterprise ● Define atemplate in the QWeb XML with the same name as the report_name field in the report action. ● Use t-foreach to loop through the product records and generate content for each one. ● Apply HTML and QWeb expressions to format and display the information. Explanation(workflow)
  • 16.
    Enterprise The Template WillGenerate the PDF Report Below
  • 17.
    Enterprise It shows howto create a custom PDF report in Odoo 18 using QWeb templates. By defining the report action and template, you can easily generate and print reports directly from Odoo. This makes it simple to add custom reports to your system. Conclusion
  • 18.
    For More Info. Checkour company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com