Create a Custom PDF Report in Odoo 16
Open-source ERP platform Odoo 16 includes robust reporting features that let companies create and alter several kinds of reports. This article will show you how to edit current reports in Odoo 16 and create bespoke PDF report from scratch. You can modify your reports to match your unique business requirements by utilizing the built-in report templates and Odoo’s flexibility.
Let’s look at creating a custom PDF report in Odoo 16 first. The QWeb template is a PDF report’s main component. To connect the report to the model, it also requires the matching action of type ir.actions.report. The report directory of a module structure should contain these two items. Let’s build a unique PDF report for the example product. Make the report action first inside the report directory. For the two components of a PDF report, we can maintain separate XML files. They are the Report action and the QWeb template. The file organization will resemble the illustration below.
The report action for the PDF Report should be in the XML file product_product_reports_xml. The ir. actions. report model contains the report action. When establishing report actions, the crucial fields that must be supplied are
The name (name)
a description of the report action. It aids in systemic report identification.
* Specify (specify)
the model with which the report is affiliated. It identifies the data model from which the required data is retrieved by the report.
(report_type) * Report Type
the kind of report to produce. One of the following is possible:
To create PDF reports using QWeb templates, use web-pdf.
web-html: Used to create HTML reports from QWeb templates.
Web-text: Used to create reports in plain text using QWeb templates.
Name of the Report (report_name)
The report’s name as it appears in the user interface.
Report File (report_file) *
The report template’s file name. The QWeb template file that was utilized to create the report is defined.
The Binding Model ID (binding_model_id)
a mention of the binding model that is connected to the report action. It outlines the model that will be used to connect other objects with the report action.
Binding Type: (binding_type)
defines the kind of binding that will be applied to the report action. One of the following is possible:
The Binding View Types (binding_view_types)
a list of view types for which the report is accessible, separated by commas. The types of views (such as form, tree, kanban, etc.) through which the report can be accessible are listed.Request Your Free Quote
The report action will add a new report to the associated model’s Print menu. A new report will be added to the model product. Product for the aforementioned report action, as shown in the snapshot below.
The template for the PDF print must be defined next. This can be done by editing the product_product_templates.xml XML file. Templates are also written in HTML/QWeb, just like website views in Odoo reports. Wkhtmltopdf is used in reporting to render PDF files. The report templates, which are for general usage, offer several variables.
time: Makes reference to the time in the default Python library.
User: The user whose record is being used to print the report.
res_company: a record for the company owned by the current user.
Website: Any active website object.
web_base_url: The base URL of the web server.
Context_timestamp: A datetime-based function.DateTime in UTC is converted to the user’s time zone for report output.
Let’s now see a sample of a straightforward report template.
The standard header and footer will be added when the template external_layout is called. The material inside the div class=”page”> will serve as the basis for the body printed inside the PDF. As seen below, the provided template will print a PDF report with the product name.
The rendering context offers a few pre-built elements. The report template provides access to these items.
* Docs: Information about the current model
*doc_ids: a list of the model’s current ids
* doc_model: record for the current model
Each field value inside the template is simple to obtain because the document item offers the records for the current model. The Odoo pdf report engine makes it simpler to customize reports because of this.
"Unlock the Full Potential of Your Business with Odoo ERP!"
"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"Get a Free Quote