Enable Dark Mode!
how-to-create-xls-report-in-doo.png
By: Niyas Raphy

How to Create a XLS Report in Odoo ?

Technical Odoo 8 Odoo 10

XLS reports are often necessary for many business organizations. Data representation and manipulation can be done in an XLS file very easily. In this blog, we will be discussing ‘how to create XLs reports in Odoo.’ As you know Odoo doesn’t’ support  XLS file creation of a report by default. So you need an extra module ‘report_xls’ for this purpose. You can download it from here: XLSX Report 

Here, we are going to create an XLS report from a wizard. Wizard can be used to enter the data. It is based on this data that we can filter the report. In the wizard, we will add some fields to filter the content of the report. So let us first look how the wizard is created.

Wizard Creation

Python file:

class
CrmReport(models.TransientModel):  
_name = 'crm.won.lost.report'    
sales_person = fields.Many2one('res.users', string="Sales Person")    
start_date = fields.Date('Start Date')    
end_date = fields.Date('End Date',default=fields.Date.today)     
def print_xls_report(self,cr,uid,ids,context=None):       
data= self.read(cr, uid, ids)[0]
return {'type': 'ir.actions.report.xml',               
'report_name': 'crm_won_lost_report.report_crm_won_lost_report.xlsx',              
'datas': data             
}

This is the python file created for the wizard. Here the fields start_date, end_date, and sales_person are filtration fields. The data in the wizard can be filtered according to the value in the fields

XML File

Wizard view:

<record id="view_crm_won_lost_report" model="ir.ui.view">    
<field name="name">CRM Report</field>    
<field name="model">crm.won.lost.report</field>    
<field name="arch" type="xml">        
<form string="Choose your details">            
<group>                
<group>                     
<field name="sales_person"  style="width: 40%%" />                
</group>                
<group>                    
<field name="start_date" />                    
<field name="end_date" />                
</group>            
</group>            
<footer>                
<button name="print_xls_report" string="Print Report" type="object"  class="oe_highlight"  />                
or                
<button string="Cancel" class="oe_link" special="cancel" groups="base.group_sale_manager"/>            
</footer>        
</form>    
</field>
</record>

This is the code for the view of the wizard (or the design of the wizard). In this view, the user can enter the filter details such as date and the salesperson. After selecting the required fields, the user can click the ‘print report’ button to print the ‘Xls’ report. When the user clicks the print button, the call goes to ‘print_xls_report’ function defined in the given model

defprint_xls_report(self,cr, uid,ids, context=None):    rec = self.browse(data)data = {}data['form'] = rec.read(['sales_person', 'start_date', 'end_date'])return self.env['report'].get_action(rec, 'crm_won_lost_report.report_crm_won_lost_report.xlsx',data=data

 In the next step, we have to define the report in the name ‘report_crm_won_lost_report’

from
openerp.addons.report_xlsx.report.report_xlsx 
import 
ReportXlsx
class 
CrmReportWonLost
(ReportXlsx):    
def
generate_xlsx_report(self,workbook,data,lines):        
#We can recieve the data entered in the wizard here as data      
sheet
= workbook.add_worksheet()
CrmReportWonLost('report.crm_won_lost_report.report_crm_won_lost_report.xlsx','crm.won.lost.report')

In the above code, we have to write the last line properly. It should be like this

Classname('report.module_name.report_name.xlsx', 'model_name')

Now we can load the report to the database.  For that, we have to add a report tag in XML,

<report    id="report_crm_xlsx"    
model="crm.won.lost.report"    
string="Won/LostReport"    
report_type="xlsx"    
name="crm_won_lost_report.report_crm_won_lost_report.xlsx"    
file="crm_won_lost_report.report_crm_won_lost_report.xlsx"    
attachment_use="False"/>

This is developed in version 9. You can follow similar steps in v8 and in v10. According to the version, we have to change the version of the ‘report_xlsx’. It can be downloaded from Odoo apps.

We already have uploaded a module using the above code in the app store, you can check and use it for reference along with this blog.


If you need any assistance in odoo, we are online, please chat with us.



9
Comments

Jesus pozzo

how to upload the report to the database ?????

25/09/2018

-

2:09PM

Jesus pozzo

in what file should I place this CrmReportWonLos class? I do not understand well what is this class

25/09/2018

-

1:59PM

Mohamed

Why there are two function with the same name print_xls_report ? i didn't understand can you explain why ? where i put the first and the second one

25/07/2018

-

7:00AM

abdessamad

hi i can't receive data from wizard can you give me an exemple? thanks in advance.

24/04/2018

-

9:23AM

Hoang Quan

return self.env['report'].get_action(rec, 'crm_won_lost_report.report_crm_won_lost_report.xlsx', where is model 'report' ? it's not for free ?

18/08/2019

-

8:22PM

Abdul Manaf

Is it possible to create an XLS report in Odoo 13?. I'm looking for an < a href="https://www.odooconsultant.com/">Odoo Consultant who can help me to implement Xls report as per my client requirment.

18/04/2020

-

2:27AM

????? ???

What's up,I log on to your blogs named "How to Create a XLS Report in Odoo ?" on a regular basis.Your story-telling style is awesome, keep up the good work! And you can look our website about ????? ???.

14/11/2017

-

5:04PM

damcong

I want to develop it on odoo 12

02/07/2019

-

10:08PM

Niyas Raphy

Hi Abdessamad, In the function generate_xlsx_report, you can receive the data from the wizard in the data

01/05/2018

-

9:00PM



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message