News & Events
Excel Report Using Controllers in Odoo | XLSX Report in Odoo
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 -
- Inside this folder, we have a custom python file (i.e., main.py) and ‘__init__.py’ file to import our custom python file.
- Inside this folder, we have the sub-folder ‘src’.
- Inside the ‘src’ folder we have a ‘js’ folder, where we will create a custom ‘js’ file (i.e., action_manager.js).
- Inside this folder, we have a custom ‘xml’ file (i.e., action_manager.xml).
- 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.
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. Please 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. The 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 The image below shows the contents of the ‘action_manager.xml’ file. This is used to add the path of the ‘action_manager.js’ file. The image below shows the contents of the ‘main.py’ (controllers) file.
The image below shows the view of the wizard.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.The above example shows the generation of a simple report in excel format using the controllers in Odoo.
"Unlock the Full Potential of Your Business with Odoo ERP!
"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"Get a Quote