Merge PR #353 into 12.0

Signed-off-by dreispt
This commit is contained in:
OCA-git-bot
2020-04-02 11:39:59 +00:00

View File

@@ -3,39 +3,48 @@
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, request from odoo.http import content_disposition, route, request
from odoo.exceptions import UserError, ValidationError
from odoo.tools.safe_eval import safe_eval from odoo.tools.safe_eval import safe_eval
import json import json
import time import time
import werkzeug
class ReportController(report.ReportController): class ReportController(report.ReportController):
@route() @route()
def report_routes(self, reportname, docids=None, converter=None, **data): def report_routes(self, reportname, docids=None, converter=None, **data):
if converter == 'xlsx': if converter == 'xlsx':
report = request.env['ir.actions.report']._get_report_from_name( try:
reportname) report = request.env['ir.actions.report']._get_report_from_name(
context = dict(request.env.context) reportname)
if docids: context = dict(request.env.context)
docids = [int(i) for i in docids.split(',')] if docids:
if data.get('options'): docids = [int(i) for i in docids.split(',')]
data.update(json.loads(data.pop('options'))) if data.get('options'):
if data.get('context'): data.update(json.loads(data.pop('options')))
# Ignore 'lang' here, because the context in data is the one if data.get('context'):
# from the webclient *but* if the user explicitely wants to # Ignore 'lang' here, because the context in data is the one
# change the lang, this mechanism overwrites it. # from the webclient *but* if the user explicitely wants to
data['context'] = json.loads(data['context']) # change the lang, this mechanism overwrites it.
if data['context'].get('lang'): data['context'] = json.loads(data['context'])
del data['context']['lang'] if data['context'].get('lang'):
context.update(data['context']) del data['context']['lang']
xlsx = report.with_context(context).render_xlsx( context.update(data['context'])
docids, data=data xlsx = report.with_context(context).render_xlsx(
)[0] docids, data=data
report_name = report.report_file )[0]
if report.print_report_name and not len(docids) > 1: report_name = report.report_file
obj = request.env[report.model].browse(docids[0]) if report.print_report_name and not len(docids) > 1:
report_name = safe_eval(report.print_report_name, obj = request.env[report.model].browse(docids[0])
{'object': obj, 'time': time}) report_name = safe_eval(report.print_report_name,
{'object': obj, 'time': time})
except (UserError, ValidationError) as odoo_error:
raise werkzeug.exceptions.HTTPException(
description='{error_name}. {error_value}'.format(
error_name=odoo_error.name,
error_value=odoo_error.value,
))
xlsxhttpheaders = [ xlsxhttpheaders = [
('Content-Type', 'application/vnd.openxmlformats-' ('Content-Type', 'application/vnd.openxmlformats-'
'officedocument.spreadsheetml.sheet'), 'officedocument.spreadsheetml.sheet'),