Скачать отчет Excel из приложения Odoo - PullRequest
0 голосов
/ 17 февраля 2019

У меня есть метод ниже, который создает файл Excel, но как я могу вернуть его как отчет Excel?

def report_excel(self,results,report_name,header,indice,title_report):
   fileExcel = xlsxwriter.Workbook('C:\\Users\\Pc-Pc\\Desktop\\411\\'+report_name+'.xlsx')
   listUsersSheet = fileExcel.add_worksheet(report_name)
   column = 0
   row = 15
   for res in results:
       listUsersSheet.merge_range(index[ind][0] + str(row+1) + ':'+ index[ind][0] + str(row + a), res[index[ind][1]], cell_format)
   fileExcel.close()

Как я могу загрузить его с клиента в виде отчета?

1 Ответ

0 голосов
/ 17 февраля 2019

Вы можете использовать веб-контроллер для этого:

from openerp.http import request
from openerp import http
from openerp.addons.web.controllers.main import serialize_exception,content_disposition


class Binary(http.Controller):
    @http.route('/web/binary/download_report', type='http', auth="public")
    @serialize_exception
    def download_xls_document(self, path, filename="My report.xlsx", **kw):
        with open(path, "rb") as pdf_file:
            return request.make_response(pdf_file.read(),
                                     [('Content-Type', 'application/octet-stream'),
                                      ('Content-Disposition', content_disposition(filename))])

и report_excel метод должен вернуть:

return {
        'type': 'ir.actions.act_url',
        'url': '/web/binary/download_report?path=%s&filename=%s' % (path, "The report name.xlsx"),
        'target': 'blank',
    }
...