Browse Source

Merge pull request #290 from Tecnativa/11.0-imp-report_xml-custom-filename

report_xml: add custom filename to response headers
pull/296/head
Pedro M. Baeza 6 years ago
committed by GitHub
parent
commit
f5a6faaa79
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      report_xml/__manifest__.py
  2. 17
      report_xml/controllers/main.py

2
report_xml/__manifest__.py

@ -4,7 +4,7 @@
{ {
"name": "XML Reports", "name": "XML Reports",
"version": "11.0.1.0.1",
"version": "11.0.1.0.2",
"category": "Reporting", "category": "Reporting",
"website": "https://github.com/OCA/reporting-engine", "website": "https://github.com/OCA/reporting-engine",
"author": "Grupo ESOC Ingeniería de Servicios, " "author": "Grupo ESOC Ingeniería de Servicios, "

17
report_xml/controllers/main.py

@ -2,8 +2,11 @@
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es> # Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html). # 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.addons.web.controllers import main as report
from odoo.http import content_disposition, route
from odoo.http import content_disposition, request, route
from odoo.tools.safe_eval import safe_eval
class ReportController(report.ReportController): class ReportController(report.ReportController):
@ -21,7 +24,17 @@ class ReportController(report.ReportController):
response.data = response.data.strip() response.data = response.data.strip()
response.headers.set("Content-Type", "text/xml") response.headers.set("Content-Type", "text/xml")
response.headers.set('Content-length', len(response.data)) response.headers.set('Content-length', len(response.data))
# set filename
action_report_obj = request.env['ir.actions.report']
report = action_report_obj._get_report_from_name(reportname)
filename = report.name
if docids:
ids = [int(x) for x in docids.split(",")]
records = request.env[report.model].browse(ids)
if report.print_report_name and not len(records) > 1:
filename = safe_eval(report.print_report_name,
{'object': records, 'time': time})
response.headers.set( response.headers.set(
'Content-Disposition', 'Content-Disposition',
content_disposition(reportname + ".xml"))
content_disposition(filename + ".xml"))
return response return response
Loading…
Cancel
Save