콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
7996 화면

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>





아바타
취소
관련 게시물 답글 화면 활동
1
1월 18
3832
0
12월 18
3923
1
6월 24
1487
1
1월 18
3488
0
7월 16
5426