|
@ -1,6 +1,6 @@ |
|
|
// © 2017 Creu Blanca
|
|
|
// © 2017 Creu Blanca
|
|
|
// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
|
|
// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
|
|
odoo.define("report_xlsx.report", function (require) { |
|
|
|
|
|
|
|
|
odoo.define("report_xlsx.report", function(require) { |
|
|
"use strict"; |
|
|
"use strict"; |
|
|
|
|
|
|
|
|
var core = require("web.core"); |
|
|
var core = require("web.core"); |
|
@ -10,36 +10,39 @@ odoo.define("report_xlsx.report", function (require) { |
|
|
var _t = core._t; |
|
|
var _t = core._t; |
|
|
|
|
|
|
|
|
ActionManager.include({ |
|
|
ActionManager.include({ |
|
|
|
|
|
|
|
|
_downloadReportXLSX: function (url, actions) { |
|
|
|
|
|
|
|
|
_downloadReportXLSX: function(url, actions) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
framework.blockUI(); |
|
|
framework.blockUI(); |
|
|
var type = "xlsx"; |
|
|
var type = "xlsx"; |
|
|
var cloned_action = _.clone(actions); |
|
|
var cloned_action = _.clone(actions); |
|
|
var new_url = url; |
|
|
var new_url = url; |
|
|
|
|
|
|
|
|
if (_.isUndefined(cloned_action.data) || |
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
_.isUndefined(cloned_action.data) || |
|
|
_.isNull(cloned_action.data) || |
|
|
_.isNull(cloned_action.data) || |
|
|
(_.isObject(cloned_action.data) && _.isEmpty(cloned_action.data))) { |
|
|
|
|
|
|
|
|
(_.isObject(cloned_action.data) && _.isEmpty(cloned_action.data)) |
|
|
|
|
|
) { |
|
|
if (cloned_action.context.active_ids) { |
|
|
if (cloned_action.context.active_ids) { |
|
|
new_url += "/" + cloned_action.context.active_ids.join(','); |
|
|
|
|
|
|
|
|
new_url += "/" + cloned_action.context.active_ids.join(","); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
new_url += "?options=" + encodeURIComponent( |
|
|
|
|
|
JSON.stringify(cloned_action.data)); |
|
|
|
|
|
new_url += "&context=" + encodeURIComponent( |
|
|
|
|
|
JSON.stringify(cloned_action.context)); |
|
|
|
|
|
|
|
|
new_url += |
|
|
|
|
|
"?options=" + |
|
|
|
|
|
encodeURIComponent(JSON.stringify(cloned_action.data)); |
|
|
|
|
|
new_url += |
|
|
|
|
|
"&context=" + |
|
|
|
|
|
encodeURIComponent(JSON.stringify(cloned_action.context)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) { |
|
|
var blocked = !session.get_file({ |
|
|
var blocked = !session.get_file({ |
|
|
url: new_url, |
|
|
url: new_url, |
|
|
data: { |
|
|
data: { |
|
|
data: JSON.stringify([new_url, type]), |
|
|
data: JSON.stringify([new_url, type]), |
|
|
}, |
|
|
}, |
|
|
success: resolve, |
|
|
success: resolve, |
|
|
error: (error) => { |
|
|
|
|
|
self.call('crash_manager', 'rpc_error', error); |
|
|
|
|
|
|
|
|
error: error => { |
|
|
|
|
|
self.call("crash_manager", "rpc_error", error); |
|
|
reject(); |
|
|
reject(); |
|
|
}, |
|
|
}, |
|
|
complete: framework.unblockUI, |
|
|
complete: framework.unblockUI, |
|
@ -48,44 +51,48 @@ odoo.define("report_xlsx.report", function (require) { |
|
|
// AAB: this check should be done in get_file service directly,
|
|
|
// AAB: this check should be done in get_file service directly,
|
|
|
// should not be the concern of the caller (and that way, get_file
|
|
|
// should not be the concern of the caller (and that way, get_file
|
|
|
// could return a deferred)
|
|
|
// could return a deferred)
|
|
|
var message = _t('A popup window with your report was blocked. You ' + |
|
|
|
|
|
'may need to change your browser settings to allow ' + |
|
|
|
|
|
'popup windows for this page.'); |
|
|
|
|
|
this.do_warn(_t('Warning'), message, true); |
|
|
|
|
|
|
|
|
var message = _t( |
|
|
|
|
|
"A popup window with your report was blocked. You " + |
|
|
|
|
|
"may need to change your browser settings to allow " + |
|
|
|
|
|
"popup windows for this page." |
|
|
|
|
|
); |
|
|
|
|
|
this.do_warn(_t("Warning"), message, true); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
_triggerDownload: function (action, options, type) { |
|
|
|
|
|
|
|
|
_triggerDownload: function(action, options, type) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
var reportUrls = this._makeReportUrls(action); |
|
|
var reportUrls = this._makeReportUrls(action); |
|
|
if (type === "xlsx") { |
|
|
if (type === "xlsx") { |
|
|
return this._downloadReportXLSX(reportUrls[type], action).then( |
|
|
return this._downloadReportXLSX(reportUrls[type], action).then( |
|
|
function () { |
|
|
|
|
|
|
|
|
function() { |
|
|
if (action.close_on_report_download) { |
|
|
if (action.close_on_report_download) { |
|
|
var closeAction = {type: 'ir.actions.act_window_close'}; |
|
|
|
|
|
return self.doAction(closeAction, _.pick( |
|
|
|
|
|
options, 'on_close')); |
|
|
|
|
|
|
|
|
var closeAction = {type: "ir.actions.act_window_close"}; |
|
|
|
|
|
return self.doAction( |
|
|
|
|
|
closeAction, |
|
|
|
|
|
_.pick(options, "on_close") |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
return options.on_close(); |
|
|
return options.on_close(); |
|
|
}); |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
return this._super.apply(this, arguments); |
|
|
return this._super.apply(this, arguments); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
_makeReportUrls: function (action) { |
|
|
|
|
|
|
|
|
_makeReportUrls: function(action) { |
|
|
var reportUrls = this._super.apply(this, arguments); |
|
|
var reportUrls = this._super.apply(this, arguments); |
|
|
reportUrls.xlsx = '/report/xlsx/' + action.report_name; |
|
|
|
|
|
|
|
|
reportUrls.xlsx = "/report/xlsx/" + action.report_name; |
|
|
return reportUrls; |
|
|
return reportUrls; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
_executeReportAction: function (action, options) { |
|
|
|
|
|
|
|
|
_executeReportAction: function(action, options) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
if (action.report_type === 'xlsx') { |
|
|
|
|
|
return self._triggerDownload(action, options, 'xlsx'); |
|
|
|
|
|
|
|
|
if (action.report_type === "xlsx") { |
|
|
|
|
|
return self._triggerDownload(action, options, "xlsx"); |
|
|
} |
|
|
} |
|
|
return this._super.apply(this, arguments); |
|
|
return this._super.apply(this, arguments); |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |