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.

37 lines
1.4 KiB

  1. # Copyright 2020 Creu Blanca
  2. # Copyright 2020 Ecosoft Co., Ltd.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. import json
  5. from werkzeug.urls import url_decode
  6. from odoo.http import request, route
  7. from odoo.addons.web.controllers import main as report
  8. class ReportController(report.ReportController):
  9. @route()
  10. def report_download(self, data, token):
  11. result = super().report_download(data, token)
  12. # When report is downloaded from print action, this function is called,
  13. # but this function cannot pass context (manually entered password) to
  14. # report.render_qweb_pdf(), encrypton for manual password is done here.
  15. requestcontent = json.loads(data)
  16. url, ttype = requestcontent[0], requestcontent[1]
  17. if (
  18. ttype in ["qweb-pdf"]
  19. and result.headers["Content-Type"] == "application/pdf"
  20. and "?" in url
  21. ):
  22. url_data = dict(url_decode(url.split("?")[1]).items())
  23. if "context" in url_data:
  24. context = json.loads(url_data["context"])
  25. if "encrypt_password" in context:
  26. Report = request.env["ir.actions.report"]
  27. data = result.get_data()
  28. encrypted_data = Report._encrypt_pdf(
  29. data, context["encrypt_password"]
  30. )
  31. result.set_data(encrypted_data)
  32. return result