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.

54 lines
2.2 KiB

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