how-to-create-xls-report-in-doo.png
Blogger_636631377605715135.png
By: Niyas Raphy

How to Create a XLS Report in Odoo ?

XLS reports are often necessary for many business organizations. Data representation and manipulation can be done in XLS file very easily. In this blog, we will be discussing ‘how to create XLs report in Odoo.’ You know by default Odoo doesn’t’ support  XLS file creation of a report. So you an extra module ‘report_xls’ and 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 and based on this data 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’

fromopenerp.addons.report_xlsx.report.report_xlsx import ReportXlsx
class CrmReportWonLost(ReportXlsx):
    defgenerate_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 the 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 above code in the app store, you can check and use it for reference along with this blog.




Comments

4

Mohamed

25/07/2018 - 7:00AM

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


abdessamad

24/04/2018 - 9:23AM

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


????? ???

14/11/2017 - 5:04PM

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 ????? ???.


Niyas Raphy

01/05/2018 - 9:00PM

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




Leave a comment

 
Calicut

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

London

Cybrosys Limited
2 Sheen Road,
Richmond, London
England - TW9 1AE

Kochi

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

Bangalore

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

Send Us A Message