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.

58 lines
1.7 KiB

  1. odoo.define("account_financial_report.report", function (require) {
  2. "use strict";
  3. require("web.dom_ready");
  4. const utils = require("report.utils");
  5. if (window.self === window.top) {
  6. return;
  7. }
  8. const web_base_url = $("html").attr("web-base-url");
  9. const trusted_host = utils.get_host_from_url(web_base_url);
  10. const trusted_protocol = utils.get_protocol_from_url(web_base_url);
  11. const trusted_origin = utils.build_origin(trusted_protocol, trusted_host);
  12. /**
  13. * Convert a model name to a capitalized title style
  14. * Example: account.mode.line --> Account Move Line
  15. *
  16. * @param {String} str
  17. * @returns {String}
  18. */
  19. function toTitleCase(str) {
  20. return str
  21. .replaceAll(".", " ")
  22. .replace(
  23. /\w\S*/g,
  24. (txt) => `${txt.charAt(0).toUpperCase()}${txt.substr(1).toLowerCase()}`
  25. );
  26. }
  27. // Allow sending commands to the webclient
  28. // `do_action` command with domain
  29. $("[res-model][domain]")
  30. .wrap("<a/>")
  31. .attr("href", "#")
  32. .on("click", function (ev) {
  33. ev.preventDefault();
  34. const res_model = $(this).attr("res-model");
  35. const action = {
  36. type: "ir.actions.act_window",
  37. res_model: res_model,
  38. domain: $(this).attr("domain"),
  39. name: toTitleCase(res_model),
  40. views: [
  41. [false, "list"],
  42. [false, "form"],
  43. ],
  44. };
  45. window.parent.postMessage(
  46. {
  47. message: "report:do_action",
  48. action: action,
  49. },
  50. trusted_origin
  51. );
  52. });
  53. });