mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
If an error occurs into the base class, the response received from the call to super is already an HTTP error response. By modifying this response we break the UI since this reponse is no more the one expeceted in case or error. This change into the initial HTTP reŝponse leeds to different kind of errors into the UI depending of the browser used. (Invalid CSRF error, UI locked in waiting response or 'Blocked a frame with origin http://localhost:8069 from accessing a cross-origin frame' or ...)
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2014 Therp BV (<http://therp.nl>).
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
import json
|
|
from openerp import http
|
|
from openerp.addons.web.controllers import main
|
|
from openerp.addons.mail.models import mail_template
|
|
|
|
|
|
class Reports(main.Reports):
|
|
@http.route('/web/report', type='http', auth="user")
|
|
@main.serialize_exception
|
|
def index(self, action, token):
|
|
result = super(Reports, self).index(action, token)
|
|
if result.status_code != 200:
|
|
# In case of error don't change the response.
|
|
return result
|
|
action = json.loads(action)
|
|
context = dict(http.request.context)
|
|
context.update(action["context"])
|
|
report_xml = http.request.env['ir.actions.report.xml']
|
|
reports = report_xml.search([
|
|
('report_name', '=', action['report_name']),
|
|
('download_filename', '!=', False)])
|
|
for report in reports:
|
|
objects = http.request.session.model(context['active_model'])\
|
|
.browse(context['active_ids'])
|
|
generated_filename = mail_template.mako_template_env\
|
|
.from_string(report.download_filename)\
|
|
.render({
|
|
'objects': objects,
|
|
'o': objects[0],
|
|
'object': objects[0],
|
|
})
|
|
result.headers['Content-Disposition'] = main.content_disposition(
|
|
generated_filename)
|
|
return result
|