×

How to Create a PDF Report Using a Button and a Wizard 5934 Views Apr 29, 2021

How to Create a PDF Report Using a Button and a Wizard

In this blog, we will learn how to create a PDF report in Odoo 14 using buttons or wizards.

Odoo is an open-source suite of business apps that assists businesses in operating and maintaining their activities. CRM, eCommerce development, web development, accounting, reporting, procurement, storage, systems integration, inventory, and many other modules are all closely integrated with Odoo.

ERP system provides a plethora of modules for carrying out various tasks to keep the education institutions operating smoothly. Administrators and teachers like to see how things are going, and they must report either to management or at a general meeting.

Odoo ERP is the world’s simplest and most popular ERP solution, with over 5 million users worldwide. Businesses and educational institutions want a comprehensive record of their activities to monitor their progress and execute flawlessly on other operational processes. Odoo also provides several study projections such as PDF, graphs and charts, data tables, and so on.

Okay, let us start with the fundamentals of Odoo before digging into PDF Reports in Odoo 14.

Wkhtmltopdf

Wkhtmltopdf is a suite of command-line tools for translating HTML pages to PDF and other image formats. We used wkhtmltopdf to create PDFs from the QWeb templates. 

In addition, although the templates are specified in HTML, wkhtmltopdf will generate a PDF report from QWeb.

QWeb

QWeb is Odoo’s primary templating engine. It is an XML templating engine that is often used to create HTML segments and pages. Template directives are XML attributes that fit this category, like t-if for conditionals, with elements and other attributes directly added.

Work of QWeb Reports

Reports, like page views in Odoo, are written in HTML/QWeb. You may use the standard QWeb control flow resources. The PDF rendering is handled by wkhtmltopdf. Reports are created by defining a report action and a report template. It is necessary to identify whether a paper format for the report is valuable or required.

Next, let’s go over how to make a pdf report.

We can render an XML file in the reports directory and don’t forget to include it in the manifest file. Here is an example of how to interpret a report action:

Create Action View

We will get a menu to generate a pdf report using the above code, as seen below.

The following is the output:

  • name: This field is required and is used to identify the report.
  • model: A model is an area that holds the name of the model from which the data is retrieved.
  • report name: This is a required field that specifies the external_id of the report template. For example, module_name.template id. 
  • print_report name: You can use Python expressions to create report file names, but it is not necessary.
  • binding_model_id: Using the print action button, if you want to print a report from a view, you must bind the action to the model. Furthermore, the value within ref should have the command line: It is ‘model_sale_order’ if the model is sale.order. Besides that, if you are attempting to print it from another place, such as a wizard or a button, you do not need to define the binding model id.
  • paperformat id: Enter the external id if the report needs a specific paper format. Here’s an example: <field name=”paperformat id” ref=”module name.paperformat id”/>.  Furthermore, if it is not specified, use the company’s default document format.

Now we will see how to build a report template.

Basically, HTML is used to build templates. The layout will be written under <template> tags. 

We can use other templates within your design by using the t-call property.

Create a template for a sales team report in the report directory and include it in the manifest file; the report id must be the same as the one specified in the above report action.

How to Print a PDF Report Using a Wizard or a Button?

The basic report will generate reports based on the model values specified in the report action. That being said, in some cases, we must take properties from various templates or obtain values from the user. In those cases, we must generate reports through wizards or other methods. As previously said, the report actions must be triggered for the report to be rendered; therefore, the print button inside the wizard or type can invoke the report action. Consider the following example.

Instead of using a function, you can simply enter the report display action id in the button for the active user to create a report.

Develop an Abstract model _get_report_values() function.

“report.report name” should be the model name. As an example, consider the following:

The following is the output:

Conclusion:

If you have any questions or concerns about the PDF Report or how to create a template in Odoo 14 using buttons and wizards, contact the experts of Brainvire.

If your educational institution needs to build an ERP with the most up-to-date modules, we will tailor a solution for you. Happy reading.

5/5 (201)

Rate Us!

Leave a Reply

Your email address will not be published. Required fields are marked *

Lets start discussing your concept

Let`s Connect