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.

47 lines
2.1 KiB

  1. # Copyright (C) 2017 Creu Blanca
  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.tools.safe_eval import safe_eval
  6. from odoo.addons.web.controllers import main as report
  7. class ReportController(report.ReportController):
  8. @route()
  9. def report_routes(self, reportname, docids=None, converter=None, **data):
  10. if converter == "xlsx":
  11. report = request.env["ir.actions.report"]._get_report_from_name(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(docids, data=data)[0]
  26. report_name = report.report_file
  27. if report.print_report_name and not len(docids) > 1:
  28. obj = request.env[report.model].browse(docids[0])
  29. report_name = safe_eval(report.print_report_name, {"object": obj})
  30. xlsxhttpheaders = [
  31. (
  32. "Content-Type",
  33. "application/vnd.openxmlformats-"
  34. "officedocument.spreadsheetml.sheet",
  35. ),
  36. ("Content-Length", len(xlsx)),
  37. ("Content-Disposition", content_disposition(report_name + ".xlsx")),
  38. ]
  39. return request.make_response(xlsx, headers=xlsxhttpheaders)
  40. return super(ReportController, self).report_routes(
  41. reportname, docids, converter, **data
  42. )