cybrosys
Published in

cybrosys

How to Create a Pdf Report in Odoo 15

ERP software contains many modules for performing various tasks to drive the flow of business operations smoothly. However, all organizations want to know their progress, and they should demonstrate the growth to the boards or authorities in the form of reports for easy handling. Odoo is one of the best business management software that is widely used by millions of users worldwide. In addition, Odoo provides the speculation of various reports such as PDF, Graphical presentation, Pivot table, XLSX report, etc.

Qweb is used as a templating engine that converts XML to HTML. It is used for defining the report templates that are in HTML format. The reports are worked based on Report Actions and Report Templates. The report actions generate the reports which are either based on a python function or a print button. We can set up a customized report using the report action in odoo v15.

This blog will define you on how to create a PDF report in Odoo 15:

Report Actions (ir.actions.report):

The following code is an example for Report actions in Odoo 15. Create this xml file in the reports directory of the module and add this file in a manifest.

The following describes the definition of each field in Report actions.

name: It is a mandatory field used to name the report.

model: model is a mandatory field, It contains the corresponding model where the data taken from.

report_type: It is used to select two types of report qweb-pdf and qweb-html.

report_name : It is a mandatory field that represents the external_id of the report template.

print_report_name: It is not a mandatory field that is used to name the generated report file using the python expressions as per the need.

binding_model_id: If you need to print the report from view, you need to define the binding_model_id, for example, the model is sale.order then the binding_model_id is model_sale_order.

How to Create a Report Template?

Templates are created in HTML format. The layout will be written inside the <template> tags. You can use more templates in a single template using t-call properties. The corresponding is an example for a sample report template.

In the example, the report_vehicle_order is the external ID that needs to be defined in the report action. Furter, the t-call=web.external_layout is used to add the default web layout of Odoo in the report. Also used t-call=web.internal_layout for minimized header and a footer view. We can customize the report corresponding to our priority.

How to Print PDF Report from Button or wizard?

In certain conditions, we need to print the report from a button or wizard. In that condition, we use the print button inside the wizard or form to call the report action that is mentioned in the previous example. The following code is an example of the print function.

The print_sample_report is the button function and the data contains the values that pass to the template. The data part is not mandatory, if no values are passed we can neglect this. If we are passing docids we can use that according to the model. After that we need to create an “Abstract model” and define _get_report_values as shown in the below code snippet.

The format of the model name is “report.report_name”. Then using the return statement you can pass the value to the report template. The “docs” contains the records and you can use it in the report template by looping in to “o” as seen in the previous template example.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cybrosys Technologies

We are Odoo Gold Partners standing par excellence in Odoo implementation, customization and allied services.