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.

88 lines
3.4 KiB

  1. // © 2017 Creu Blanca
  2. // License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
  3. odoo.define("report_xlsx.report", function (require) {
  4. "use strict";
  5. var core = require("web.core");
  6. var ActionManager = require("web.ActionManager");
  7. var crash_manager = require("web.crash_manager");
  8. var framework = require("web.framework");
  9. var session = require("web.session");
  10. var _t = core._t;
  11. ActionManager.include({
  12. _downloadReportXLSX: function (url, actions) {
  13. framework.blockUI();
  14. var def = $.Deferred();
  15. var type = "xlsx";
  16. var cloned_action = _.clone(actions);
  17. if (_.isUndefined(cloned_action.data) ||
  18. _.isNull(cloned_action.data) ||
  19. (_.isObject(cloned_action.data) && _.isEmpty(cloned_action.data)))
  20. {
  21. if (cloned_action.context.active_ids) {
  22. url += "/" + cloned_action.context.active_ids.join(',');
  23. }
  24. } else {
  25. url += "?options=" + encodeURIComponent(JSON.stringify(cloned_action.data));
  26. url += "&context=" + encodeURIComponent(JSON.stringify(cloned_action.context));
  27. }
  28. var blocked = !session.get_file({
  29. url: url,
  30. data: {
  31. data: JSON.stringify([url, type]),
  32. },
  33. success: def.resolve.bind(def),
  34. error: function () {
  35. crash_manager.rpc_error.apply(crash_manager, arguments);
  36. def.reject();
  37. },
  38. complete: framework.unblockUI,
  39. });
  40. if (blocked) {
  41. // AAB: this check should be done in get_file service directly,
  42. // should not be the concern of the caller (and that way, get_file
  43. // could return a deferred)
  44. var message = _t('A popup window with your report was blocked. You ' +
  45. 'may need to change your browser settings to allow ' +
  46. 'popup windows for this page.');
  47. this.do_warn(_t('Warning'), message, true);
  48. }
  49. return def;
  50. },
  51. _triggerDownload: function (action, options, type) {
  52. var self = this;
  53. var reportUrls = this._makeReportUrls(action);
  54. if (type === "xlsx") {
  55. return this._downloadReportXLSX(reportUrls[type], action).then(function () {
  56. if (action.close_on_report_download) {
  57. var closeAction = {type: 'ir.actions.act_window_close'};
  58. return self.doAction(closeAction, _.pick(options, 'on_close'));
  59. } else {
  60. return options.on_close();
  61. }
  62. });
  63. }
  64. return this._super.apply(this, arguments);
  65. },
  66. _makeReportUrls: function (action) {
  67. var reportUrls = this._super.apply(this, arguments);
  68. reportUrls.xlsx = '/report/xlsx/' + action.report_name;
  69. return reportUrls;
  70. },
  71. _executeReportAction: function (action, options) {
  72. var self = this;
  73. if (action.report_type === 'xlsx') {
  74. return self._triggerDownload(action, options, 'xlsx');
  75. }
  76. return this._super.apply(this, arguments);
  77. }
  78. });
  79. });