mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[MIG] report_csv: Backport from 11.0
This commit is contained in:
@@ -7,41 +7,48 @@ var ActionManager= require('web.ActionManager');
|
||||
var crash_manager = require('web.crash_manager');
|
||||
var framework = require('web.framework');
|
||||
|
||||
var trigger_download = function(session, response, c, action, options) {
|
||||
session.get_file({
|
||||
url: '/report/download',
|
||||
data: {data: JSON.stringify(response)},
|
||||
complete: framework.unblockUI,
|
||||
error: c.rpc_error.bind(c),
|
||||
success: function(){
|
||||
if (action && options && !action.dialog) {
|
||||
options.on_close();
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
ActionManager.include({
|
||||
ir_actions_report: function (action, options){
|
||||
ir_actions_report_xml: function(action, options) {
|
||||
var self = this;
|
||||
var cloned_action = _.clone(action);
|
||||
if (cloned_action.report_type === 'csv') {
|
||||
|
||||
// Py3o reports
|
||||
if ('report_type' in action && action.report_type == 'csv' ) {
|
||||
framework.blockUI();
|
||||
var report_csv_url = 'report/csv/' + cloned_action.report_name;
|
||||
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(',');
|
||||
action = _.clone(action);
|
||||
var report_url = '/report/csv/' + action.report_name;;
|
||||
// generic report: no query string
|
||||
// particular: query string of action.data.form and context
|
||||
if (!('data' in action) || !(action.data)) {
|
||||
if ('active_ids' in action.context) {
|
||||
report_url += "/" + 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));
|
||||
report_url += "&options=" + encodeURIComponent(JSON.stringify(action.data));
|
||||
report_url += "&context=" + encodeURIComponent(JSON.stringify(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();
|
||||
}
|
||||
}
|
||||
});
|
||||
framework.unblockUI();
|
||||
return;
|
||||
|
||||
var response = new Array();
|
||||
response[0] = report_url;
|
||||
response[1] = action.report_type;
|
||||
var c = crash_manager;
|
||||
return trigger_download(self.session, response, c, action, options);
|
||||
} else {
|
||||
return self._super(action, options);
|
||||
}
|
||||
return self._super(action, options);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user