Generate XLS Report in Odoo

Posted By : Piyush Khandelwal | 31-May-2020

Generate XLS Report in Odoo

 

XLS reports are typically necessary and useful for business organizations. Illustration and manipulation of data are often done via XLS files. In this article, we will be learning How to generate XLS reports in Odoo. By default, Odoo doesn’t provide the functionality to generate reports in XLS format. To add this functionality, we use an additional module named Base Report XLSX.

Prerequisites

  1. You must have python 3 installed in your system.
  2. You must have Odoo 12 already running in your System.
  3. Download and Add this module in the addons folder, Base Report XLSX.
  4. You have installed the xlsxwriter package in your system.

To install xlsxwriter, you can use pip.

pip3 install xlsxwriter

Now, we will be generating an XLS report for the res.partner model by using an AbstractModel Class. Below, is an example to generate the XLS report on a module called practice.

 

from odoo import models

class PracticePartnerXlsx(models.AbstractModel):

    _name = 'report.practice.partner_report'

    _inherit = 'report.report_xlsx.abstract'

    def generate_xlsx_report(self, workbook, data, records):

            sheet = workbook.add_worksheet('Partner Report')

            bold_format = workbook.add_format({'bold': True}) #This to add bold formatting to the cells

            count_num =0 # To track the row number

            for obj in records: # Looping on the recordset , to get the name of individual record

                sheet.write(count_num, 0, obj.name, bold_format) #(row, col, data, format) 

                count_num= count_num + 1 # Incrementing the value by 1, to track the row

                

To know, more about the sheet and workbook obj, please refer to the documentation of Xlsxwriter.

Now, we have to create a report record to be able to generate this XLS Report.

        <report

                id="practice_partner_report_xlsx"

                model="res.partner"

                string="Partners Excel Report"

                report_type="xlsx"

                name="practice.partner_report"

                file="practice.partner_report"

                print_report_name="Partners Excel Report"

        />

Conclusion

Now you should be able to generate an Excel Report for res.partner model. This code is for odoo version 12. You can follow similar steps for other versions too.You'll just have to change the version of the Base Report XLSX module.

 

We are an ERP Development Company with the goal of streamlining enterprise operations to maximize growth and profit. Our Odoo development services range from end to end ERP implementation to developing custom modules, and providing maintenance and support. Get in touch with us to implement Odoo modules in your ERP now.


 

 

 

 


Please remove URL from text

Comment is required

Sending message..
Connect with us