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

  • Odoo ERP

  • Published On April 29, 2021

Featured Image
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.

[Also read: Why Should You Hire An Odoo Partner?]

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. People often use XML templating engine 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.
Discover your true business potential with the help of Brainvire’s dynamic Odoo ERP Migration Services.

Work of QWeb Reports

In Odoo, developers use HTML/QWeb to write reports, including page views. You may use the standard QWeb control flow resources. To create reports with Odoo, you need to define both a report action and a report template. The PDF rendering for these reports is handled by wkhtmltopdf. It is necessary to identify whether a paper format for the report is valuable or required.

[Also read: How different is Odoo 15 from Odoo 14?]

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.
If you are looking for the right Odoo ERP Development Services to take your business to the next-level, contact Brainvire today.

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. However, in certain situations, it may be necessary to extract properties from multiple templates or retrieve user-defined values. In those cases, we must generate reports through wizards or other methods. To create a report in Odoo, you need to trigger the report action. This can be done using the print button in the wizard or through the type that is linked to the report action.

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.

[Also read: 10 New features of Odoo 15 that will entice you to upgrade]

Develop an Abstract model _get_report_values() function.

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

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.

FAQs

What is the use of Wkhtmltopdf?

Wkhtmltopdf is an open-source command-line tool. As its name suggests, Wk-html-to-pdf can efficiently convert HTML pages/single webpages/cover webpages/a table of contents into PDF documents. Wkhtmltoimage is another tool to help you render HTML pages into IMG formats like JPG/PNG/etc. Both these tools use the Qt WebKit rendering engine for conversion.

How to create PDF report in Odoo 15?

Create an XML file in the Reports Directory. Ensure that you include it in the Manifest File. A menu to generate a PDF report will appear. The output will consist of several fields: name, model, report name, print_report name, binding_model_id, and paperformat id. Once you define the fields, you can create a Report Template. While HTML is used to build these templates, you can use other templates using the t-call property.

How do I create a QWEB report in Odoo 13?

Create a new XML file to place under your ModuleName/views. Define the template IDs and names Odoo will use to find the correct report. Add this report to the XML file responsible for reports and import them in a module using the _openerp_.py file. Ensure that you add the new XML file to this list. Reload your module by a command or an update and your new report will show up.

    Ready for Digital Transformation?

    Ask our team for custom made business growth plan.

    Hiren Raval
    About Author
    Hiren Raval

    Hiren is a seasoned eCommerce consultant who has helped many businesses succeed. He's worked with companies of all sizes to help them find the right solutions and strategies to grow their business. If you need someone who can guide your company through this new landscape, Hiren is the person for you. Get in touch with him today!

    Related Articles

    • Design engaging Commission Email Templates with Odoo
      Quickly Create Sales Engaging Commission Email Templates With Odoo

      Writing good emails is vital to maintain professionalism, but you would not want to write the same structure of email again and, would you? That is where email templates come

    • How to Transfer Files Securely and Quickly with SCP
      How to Transfer Files with Secure Copy Protocol (SCP)?

      What is SCP and How does it Work? SCP stands for Secure Copy Protocol that allows for the creation of a “self-contained” program. In other words, the file combined with

    • 10 New features of Odoo 15 that will entice you to upgrade
      10 New features of Odoo 15 that will entice you to upgrade

      Based on Odoo’s previous year’s standard and plan, a new version has been released every year since 2014, and this trend is anticipated to continue in the future. Every new