Excel Report Using Controllers in Odoo | XLSX Report in Odoo

TEAM-BASSAM
December 16, 2022

Reporting plays a crucial role in analyzing and understanding various operations or activities taking place inside an organization. Be it monitoring accounts or finance-related aspects or getting an overview of your stock, reports play a major role. Reports generated in Odoo are mainly of two formats – pdf or excel.

Excel reports, in particular, are very easy to understand and simple to use and help the user analyze the contents easily and efficiently. But Odoo doesn’t support xlsx report creation by default. In most cases, in order to generate an xlsx report, an external module (report_xlsx) is used. There is an alternate method to generate xlsx report in Odoo without using the external module. In this blog, we will look into the steps associated with creating an Odoo xlsx report without using the external module.

The alternate method of xlsx creation involves the use of ‘controllers’. Here we can look into an example of an xlsx report being generated from a wizard using the controllers.

The image below shows our module for xlsx report generation. Apart from the ‘__manifest__.py’ and ‘__init__.py’ files it contains the following folders –

  1. controllers
    1. Inside this folder, we have a custom python file (i.e., main.py) and ‘__init__.py’ file to import our custom python file.
  2. static
    1. Inside this folder, we have the sub-folder ‘src’.
    2. Inside the ‘src’ folder we have a ‘js’ folder, where we will create a custom ‘js’ file (i.e., action_manager.js).
  3. views
    1. Inside this folder, we have a custom ‘xml’ file (i.e., action_manager.xml).
  4. wizard
    1. Inside this folder, we have a custom python file (i.e., wizard.py), a custom ‘xml’ file (i.e., wizard_view.xml) and ‘__init__.py’ file to import our custom python file.
                                                 import-custom-python-file
After creating the required folders and files, we can now look into the contents of each file.

The image below shows the contents of the ‘wizard.py’ file.

‘wizard-py’-contentsPlease note that we have imported the ‘xlsxwriter’ in this python file. Also, there are 2 functions defined here. ‘print_xlsx’ is the button action from the wizard to print the xlsx report and ‘get_xlsx_report’ is used to write the data into the xlsx report. We can also add formats, contents, etc. in the ‘get_xlsx_report’ function.

The image below shows the contents of the ‘wizard_view.xml’ file.

contents-of-‘wizard_view-xml’-fileThe image below shows the contents of the ‘action_manager.js’ file. This will be used by the ‘Action Manager’ to execute the report action while returning the ‘report_type : xlsx’ in the ‘wizard.py’ file. The “url : ‘/xlsx_reports’” is directed to the controllers.

Request Your Free Quote
contents-of-‘action_manager-jsThe image below shows the contents of the ‘action_manager.xml’ file. This is used to add the path of the ‘action_manager.js’ file.

xlsx-report-in-odoo

The image below shows the contents of the ‘main.py’ (controllers) file.

contents-of-‘main-py’-file

The image below shows the view of the wizard.

xlsx-report-in-odoo

When the ‘PRINT’ button from the wizard is clicked, the controller calls the ‘get_xlsx_report()’ function defined in the ‘wizard.py’ file. This will automatically give us the output in xlsx format.

The image below shows the output, i.e., the xlsx report.

output-of-excel-reports-in-odoo

The above example shows the generation of a simple report in excel format using the controllers in Odoo.

DOWNLOAD ERP

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

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