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.

50 lines
1.9 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.http import content_disposition, request, route
  5. from odoo.addons.report_xlsx.controllers.main import ReportController
  6. class ReportController(ReportController):
  7. @route(
  8. [
  9. "/report/<converter>/<reportname>",
  10. "/report/<converter>/<reportname>/<docids>",
  11. ],
  12. type="http",
  13. auth="user",
  14. website=True,
  15. )
  16. def report_routes(self, reportname, docids=None, converter=None, **data):
  17. report = request.env["ir.actions.report"]._get_report_from_name(reportname)
  18. if converter == "xlsx" and not report:
  19. context = dict(request.env.context)
  20. if docids:
  21. docids = [int(i) for i in docids.split(",")]
  22. if data.get("options"):
  23. data.update(json.loads(data.pop("options")))
  24. if data.get("context"):
  25. data["context"] = json.loads(data["context"])
  26. context.update(data["context"])
  27. context["report_name"] = reportname
  28. xlsx = report.with_context(context)._render_xlsx(docids, data=data)[0]
  29. report_file = context.get("report_file")
  30. if not report_file:
  31. active_model = context.get("active_model", "export")
  32. report_file = active_model.replace(".", "_")
  33. xlsxhttpheaders = [
  34. (
  35. "Content-Type",
  36. "application/vnd.openxmlformats-"
  37. "officedocument.spreadsheetml.sheet",
  38. ),
  39. ("Content-Length", len(xlsx)),
  40. ("Content-Disposition", content_disposition(report_file + ".xlsx")),
  41. ]
  42. return request.make_response(xlsx, headers=xlsxhttpheaders)
  43. return super().report_routes(reportname, docids, converter, **data)