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.

57 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.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. # Ignore 'lang' here, because the context in data is the one
  26. # from the webclient *but* if the user explicitely wants to
  27. # change the lang, this mechanism overwrites it.
  28. data["context"] = json.loads(data["context"])
  29. if data["context"].get("lang"):
  30. del data["context"]["lang"]
  31. context.update(data["context"])
  32. context["report_name"] = reportname
  33. xlsx = report.with_context(context).render_xlsx(docids, data=data)[0]
  34. report_file = context.get("report_file")
  35. if not report_file:
  36. active_model = context.get("active_model", "export")
  37. report_file = active_model.replace(".", "_")
  38. xlsxhttpheaders = [
  39. (
  40. "Content-Type",
  41. "application/vnd.openxmlformats-"
  42. "officedocument.spreadsheetml.sheet",
  43. ),
  44. ("Content-Length", len(xlsx)),
  45. ("Content-Disposition", content_disposition(report_file + ".xlsx")),
  46. ]
  47. return request.make_response(xlsx, headers=xlsxhttpheaders)
  48. return super(ReportController, self).report_routes(
  49. reportname, docids, converter, **data
  50. )