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
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. import time
  5. from odoo.http import content_disposition, request, route
  6. from odoo.tools.safe_eval import safe_eval
  7. from odoo.addons.web.controllers import main as report
  8. class ReportController(report.ReportController):
  9. @route()
  10. def report_routes(self, reportname, docids=None, converter=None, **data):
  11. if converter == "xlsx":
  12. report = request.env["ir.actions.report"]._get_report_from_name(reportname)
  13. context = dict(request.env.context)
  14. if docids:
  15. docids = [int(i) for i in docids.split(",")]
  16. if data.get("options"):
  17. data.update(json.loads(data.pop("options")))
  18. if data.get("context"):
  19. # Ignore 'lang' here, because the context in data is the one
  20. # from the webclient *but* if the user explicitely wants to
  21. # change the lang, this mechanism overwrites it.
  22. data["context"] = json.loads(data["context"])
  23. if data["context"].get("lang"):
  24. del data["context"]["lang"]
  25. context.update(data["context"])
  26. xlsx = report.with_context(context).render_xlsx(docids, data=data)[0]
  27. report_name = report.report_file
  28. if report.print_report_name and not len(docids) > 1:
  29. obj = request.env[report.model].browse(docids[0])
  30. report_name = safe_eval(
  31. report.print_report_name, {"object": obj, "time": time}
  32. )
  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_name + ".xlsx")),
  41. ]
  42. return request.make_response(xlsx, headers=xlsxhttpheaders)
  43. return super(ReportController, self).report_routes(
  44. reportname, docids, converter, **data
  45. )