[12.0][MIG] report_csv

This commit is contained in:
Jaime Arroyo
2019-07-02 16:56:20 +02:00
committed by ferran-73
parent 1fad3828ec
commit 08a9531f01
7 changed files with 165 additions and 52 deletions

View File

@@ -1,47 +1,88 @@
// © 2019 Creu Blanca
// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
odoo.define('report_csv.report', function(require){
'use strict';
odoo.define("report_csv.report", function (require) {
"use strict";
var ActionManager= require('web.ActionManager');
var crash_manager = require('web.crash_manager');
var framework = require('web.framework');
var core = require("web.core");
var ActionManager = require("web.ActionManager");
var crash_manager = require("web.crash_manager");
var framework = require("web.framework");
var session = require("web.session");
var _t = core._t;
ActionManager.include({
ir_actions_report: function (action, options){
var self = this;
var cloned_action = _.clone(action);
if (cloned_action.report_type === 'csv') {
ActionManager.include({
_downloadReportCSV: function (url, actions) {
framework.blockUI();
var report_csv_url = 'report/csv/' + cloned_action.report_name;
var def = $.Deferred();
var type = "csv";
var cloned_action = _.clone(actions);
if (_.isUndefined(cloned_action.data) ||
_.isNull(cloned_action.data) ||
(_.isObject(cloned_action.data) && _.isEmpty(cloned_action.data)))
{
if(cloned_action.context.active_ids) {
report_csv_url += '/' + cloned_action.context.active_ids.join(',');
if (cloned_action.context.active_ids) {
url += "/" + cloned_action.context.active_ids.join(',');
}
} else {
report_csv_url += '?options=' + encodeURIComponent(JSON.stringify(cloned_action.data));
report_csv_url += '&context=' + encodeURIComponent(JSON.stringify(cloned_action.context));
url += "?options=" + encodeURIComponent(JSON.stringify(cloned_action.data));
url += "&context=" + encodeURIComponent(JSON.stringify(cloned_action.context));
}
self.getSession().get_file({
url: report_csv_url,
data: {data: JSON.stringify([
report_csv_url,
cloned_action.report_type
])},
error: crash_manager.rpc_error.bind(crash_manager),
success: function (){
if(cloned_action && options && !cloned_action.dialog){
options.on_close();
}
}
var blocked = !session.get_file({
url: url,
data: {
data: JSON.stringify([url, type]),
},
success: def.resolve.bind(def),
error: function () {
crash_manager.rpc_error.apply(crash_manager, arguments);
def.reject();
},
complete: framework.unblockUI,
});
framework.unblockUI();
return;
if (blocked) {
// AAB: this check should be done in get_file service directly,
// should not be the concern of the caller (and that way, get_file
// 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);
}
return def;
},
_triggerDownload: function (action, options, type) {
var self = this;
var reportUrls = this._makeReportUrls(action);
if (type === "csv") {
return this._downloadReportCSV(reportUrls[type], action).then(function () {
if (action.close_on_report_download) {
var closeAction = {type: 'ir.actions.act_window_close'};
return self.doAction(closeAction, _.pick(options, 'on_close'));
} else {
return options.on_close();
}
});
}
return this._super.apply(this, arguments);
},
_makeReportUrls: function (action) {
var reportUrls = this._super.apply(this, arguments);
reportUrls.csv = '/report/csv/' + action.report_name;
return reportUrls;
},
_executeReportAction: function (action, options) {
var self = this;
if (action.report_type === 'csv') {
return self._triggerDownload(action, options, 'csv');
}
return this._super.apply(this, arguments);
}
return self._super(action, options);
}
});
});
});