Dear Community,
I am building module, to download a report in xls format using xlwt in odoo 11.0, but cannot download with .xls extension,when downloading system is asking and external application to open with. Any help will be appreciated.
Here is the code I am using:
Python
wrk_bk = xlwt.Workbook()
wrk_sht = wrk_bk.add_sheet('Report')
wrk_sht.write(3,0,'Customer Name')
wrk_sht.set_portrait(False)
wrk_bk.save('/tmp/report.xls')
result_file = open('/tmp/report.xls','rb').read()
self.env.cr.execute("""DELETE FROM wizard_report""")
report_vals = {
'report_name': 'Report.xls',
'report':base64.encodestring(result_file)
}
attach_id = self.env['wizard.report'].create(report_vals)
return {
'name': _('Download Report'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'wizard.report',
'res_id': attach_id.id,
'context': self.env.context,
'type': 'ir.actions.act_window',
'target':'new'
}
class WizardReport(models.TransientModel):
_name = "wizard.report"
report = fields.Binary('Prepared file', filters='.xls', readonly=True)
report_name = fields.Char('File Name', size=32)
_defaults = {
'report_name': 'Contract Report.xls',
}
XML
<h1>
<field name="report_name" invisible="1"/>
<field widget="binary" name="report" filename="name"/>
</h1>