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.8 KiB

  1. odoo.define("account_financial_report.client_action", function (require) {
  2. "use strict";
  3. var ReportAction = require("report.client_action");
  4. var core = require("web.core");
  5. var QWeb = core.qweb;
  6. const AFRReportAction = ReportAction.extend({
  7. start: function () {
  8. return this._super.apply(this, arguments).then(() => {
  9. this.$buttons = $(
  10. QWeb.render(
  11. "account_financial_report.client_action.ControlButtons",
  12. {}
  13. )
  14. );
  15. this.$buttons.on("click", ".o_report_print", this.on_click_print);
  16. this.$buttons.on("click", ".o_report_export", this.on_click_export);
  17. this.controlPanelProps.cp_content = {
  18. $buttons: this.$buttons,
  19. };
  20. this._controlPanelWrapper.update(this.controlPanelProps);
  21. });
  22. },
  23. on_click_export: function () {
  24. const action = {
  25. type: "ir.actions.report",
  26. report_type: "xlsx",
  27. report_name: this._get_xlsx_name(this.report_name),
  28. report_file: this._get_xlsx_name(this.report_file),
  29. data: this.data,
  30. context: this.context,
  31. display_name: this.title,
  32. };
  33. return this.do_action(action);
  34. },
  35. /**
  36. * @param {String} str
  37. * @returns {String}
  38. */
  39. _get_xlsx_name: function (str) {
  40. if (!_.isString(str)) {
  41. return str;
  42. }
  43. const parts = str.split(".");
  44. return `a_f_r.report_${parts[parts.length - 1]}_xlsx`;
  45. },
  46. });
  47. core.action_registry.add("account_financial_report.client_action", AFRReportAction);
  48. return AFRReportAction;
  49. });