Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
7827 Переглядів

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>

















Аватар
Відмінити
Найкраща відповідь

You can add button in wizard, when click on it you can download report.

You can return action that should return action as following :

<button name="download_report" string="Download" type="object"/>

def download_report(self):

     return

     {

     'type' : 'ir.actions.act_url','url':

     'web/content/?model=wizard.report&field=report&download=true&id=%s&filename=%s'%(self.id,report_name),

     'target': 'new',

     }

Аватар
Відмінити
Найкраща відповідь

As a suggestion you can use the OCA module

https://www.odoo.com/apps/modules/11.0/report_xlsx/

and to print the report using a wizard.


from odoo import models

class WizzExample(models.TransientModel):

_name = 'wizz.example'

partner_id = fields.Many2many('res.partner', string='Partner')

# button

@api.multi

def print_report(self):

return self.env.ref('your_module.report_partner_xlsx').report_action(self)

#file in report

from odoo import models

class PartnerXlsx(models.AbstractModel):

_name = 'report.your_module.report_partner_xlsx'

_inherit = 'report.report_xlsx.abstract'

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

for line in obj:

sheet = workbook.add_worksheet('Report')

bold = workbook.add_format({'bold': True})

sheet.write(0, 0, line.partner_id.name, bold)

<?xml version="1.0" encoding="UTF-8" ?>

<odoo>

<report

id="report_partner_xlsx"

model="wizz.example"

string="Print to XLSX"

report_type="xlsx"

name="your_module.report_partner_xlsx"

file="Report partner"

attachment_use="False"

/>

</odoo>





Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
Financial Excel Report Вирішено
1
січ. 18
3697
0
груд. 18
3781
1
черв. 24
1346
1
січ. 18
3377
0
лип. 16
5260