Skip to content

Commit

Permalink
Merge b58ce64 into 8cea303
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdauden authored Oct 17, 2019
2 parents 8cea303 + b58ce64 commit dda6de7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions report_xlsx/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A python class ::
class PartnerXlsx(models.AbstractModel):
_name = 'report.module_name.report_name'
_inherit = 'report.report_xlsx.abstract'

def generate_xlsx_report(self, workbook, data, partners):
for obj in partners:
report_name = obj.name
Expand All @@ -45,7 +45,7 @@ To manipulate the ``workbook`` and ``sheet`` objects, refer to the

A report XML record ::

<report
<report
id="partner_xlsx"
model="res.partner"
string="Print to XLSX"
Expand Down Expand Up @@ -75,6 +75,9 @@ Contributors

* Adrien Peiffer <adrien.peiffer@acsone.eu>
* Enric Tobella <etobella@creublanca.es>
* `Tecnativa <https://www.tecnativa.com/>`_:

* Carlos Dauden

Maintainer
----------
Expand Down
12 changes: 11 additions & 1 deletion report_xlsx/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Copyright (C) 2017 Creu Blanca
# Copyright 2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).

import time

from odoo.addons.web.controllers import main as report
from odoo.http import content_disposition, route, request
from odoo.tools.safe_eval import safe_eval

import json

Expand All @@ -14,8 +18,14 @@ def report_routes(self, reportname, docids=None, converter=None, **data):
report = request.env['ir.actions.report']._get_report_from_name(
reportname)
context = dict(request.env.context)
filename = "%s.%s" % (report.name, "xlsx")
if docids:
docids = [int(i) for i in docids.split(',')]
obj = request.env[report.model].browse(docids)
if report.print_report_name and not len(obj) > 1:
report_name = safe_eval(report.print_report_name,
{'object': obj, 'time': time})
filename = "%s.%s" % (report_name, "xlsx")
if data.get('options'):
data.update(json.loads(data.pop('options')))
if data.get('context'):
Expand All @@ -35,7 +45,7 @@ def report_routes(self, reportname, docids=None, converter=None, **data):
('Content-Length', len(xlsx)),
(
'Content-Disposition',
content_disposition(report.report_file + '.xlsx')
content_disposition(filename)
)
]
return request.make_response(xlsx, headers=xlsxhttpheaders)
Expand Down

0 comments on commit dda6de7

Please sign in to comment.