OCA reporting engine fork for dev and update.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.8 KiB

  1. # Copyright (C) 2017 Creu Blanca
  2. # License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
  3. from odoo.addons.web.controllers import main as report
  4. from odoo.http import route, request
  5. import json
  6. class ReportController(report.ReportController):
  7. @route()
  8. def report_routes(self, reportname, docids=None, converter=None, **data):
  9. if converter == 'xlsx':
  10. report = request.env['ir.actions.report']._get_report_from_name(
  11. reportname)
  12. context = dict(request.env.context)
  13. if docids:
  14. docids = [int(i) for i in docids.split(',')]
  15. if data.get('options'):
  16. data.update(json.loads(data.pop('options')))
  17. if data.get('context'):
  18. # Ignore 'lang' here, because the context in data is the one
  19. # from the webclient *but* if the user explicitely wants to
  20. # change the lang, this mechanism overwrites it.
  21. data['context'] = json.loads(data['context'])
  22. if data['context'].get('lang'):
  23. del data['context']['lang']
  24. context.update(data['context'])
  25. xlsx = report.with_context(context).render_xlsx(
  26. docids, data=data
  27. )[0]
  28. xlsxhttpheaders = [
  29. ('Content-Type', 'application/vnd.openxmlformats-'
  30. 'officedocument.spreadsheetml.sheet'),
  31. ('Content-Length', len(xlsx)),
  32. (
  33. 'Content-Disposition',
  34. 'attachment; filename=' + report.report_file + '.xlsx'
  35. )
  36. ]
  37. return request.make_response(xlsx, headers=xlsxhttpheaders)
  38. return super(ReportController, self).report_routes(
  39. reportname, docids, converter, **data
  40. )