GoodERP
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

40 lines
1.6KB

  1. /** @odoo-module **/
  2. import {WARNING_MESSAGE, WKHTMLTOPDF_MESSAGES, _getReportUrl} from "./tools.esm";
  3. import {_t} from "web.core";
  4. import {registry} from "@web/core/registry";
  5. /* eslint-disable init-declarations */
  6. let wkhtmltopdfStateProm;
  7. registry
  8. .category("ir.actions.report handlers")
  9. .add("open_report_handler", async function (action, options, env) {
  10. if (action.type === "ir.actions.report" && action.report_type === "qweb-pdf") {
  11. // Check the state of wkhtmltopdf before proceeding
  12. if (!wkhtmltopdfStateProm) {
  13. wkhtmltopdfStateProm = env.services.rpc("/report/check_wkhtmltopdf");
  14. }
  15. const state = await wkhtmltopdfStateProm;
  16. if (state in WKHTMLTOPDF_MESSAGES) {
  17. env.services.notification.add(WKHTMLTOPDF_MESSAGES[state], {
  18. sticky: true,
  19. title: _t("Report"),
  20. });
  21. }
  22. if (state === "upgrade" || state === "ok") {
  23. // Trigger the download of the PDF report
  24. const url = _getReportUrl(action, "pdf", env);
  25. // AAB: this check should be done in get_file service directly,
  26. // should not be the concern of the caller (and that way, get_file
  27. // could return a deferred)
  28. if (!window.open(url)) {
  29. env.services.notification.add(WARNING_MESSAGE, {
  30. type: "warning",
  31. });
  32. }
  33. }
  34. return Promise.resolve(true);
  35. }
  36. return Promise.resolve(false);
  37. });
上海开阖软件有限公司 沪ICP备12045867号-1