2014-02-18 10:49:59 +00:00
|
|
|
openerp.report = function(instance) {
|
2014-03-21 16:47:16 +00:00
|
|
|
var wkhtmltopdf_state;
|
2014-02-18 10:49:59 +00:00
|
|
|
|
|
|
|
instance.web.ActionManager = instance.web.ActionManager.extend({
|
|
|
|
ir_actions_report_xml: function(action, options) {
|
|
|
|
var self = this;
|
|
|
|
instance.web.blockUI();
|
|
|
|
action = _.clone(action);
|
2014-02-27 15:40:46 +00:00
|
|
|
_t = instance.web._t;
|
2014-02-18 10:49:59 +00:00
|
|
|
|
|
|
|
// QWeb reports
|
2014-02-21 16:33:20 +00:00
|
|
|
if ('report_type' in action && (action.report_type == 'qweb-html' || action.report_type == 'qweb-pdf' || action.report_type == 'controller')) {
|
2014-03-21 16:47:16 +00:00
|
|
|
var report_url = '';
|
2014-02-21 16:33:20 +00:00
|
|
|
switch (action.report_type) {
|
|
|
|
case 'qweb-html':
|
|
|
|
report_url = '/report/' + action.report_name;
|
|
|
|
break;
|
|
|
|
case 'qweb-pdf':
|
|
|
|
report_url = '/report/pdf/report/' + action.report_name;
|
|
|
|
break;
|
|
|
|
case 'controller':
|
|
|
|
report_url = action.report_file;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
report_url = '/report/' + action.report_name;
|
|
|
|
break;
|
2014-02-18 10:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// single/multiple id(s): no query string
|
|
|
|
// wizard: query string of action.datas.form
|
|
|
|
if (!('datas' in action)) {
|
|
|
|
if ('active_ids' in action.context) {
|
|
|
|
report_url += "/" + action.context.active_ids.join(',');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_.each(action.datas.form, function(value, key) {
|
|
|
|
// will be erased when all wizards are rewritten
|
2014-02-21 16:33:20 +00:00
|
|
|
if (key.substring(0, 12) === 'used_context') {
|
2014-02-18 10:49:59 +00:00
|
|
|
delete action.datas.form[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($.type(value) === 'array') {
|
|
|
|
action.datas.form[key] = value.join(',');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
report_url += "?" + $.param(action.datas.form);
|
|
|
|
}
|
2014-03-21 18:36:49 +00:00
|
|
|
if (action.report_type == 'qweb-html') {
|
2014-02-18 12:53:22 +00:00
|
|
|
// Open the html report in a popup
|
2014-03-21 10:58:06 +00:00
|
|
|
window.open(report_url, '_blank', 'height=900,width=1280');
|
2014-02-18 12:53:22 +00:00
|
|
|
instance.web.unblockUI();
|
|
|
|
return;
|
|
|
|
} else {
|
2014-03-21 18:36:49 +00:00
|
|
|
// Trigger the download of the pdf/controller report
|
2014-02-18 12:53:22 +00:00
|
|
|
var c = openerp.webclient.crashmanager;
|
2014-03-21 16:47:16 +00:00
|
|
|
var response = new Array();
|
|
|
|
response[0] = report_url;
|
|
|
|
response[1] = action.report_type;
|
2014-02-21 16:33:20 +00:00
|
|
|
|
2014-03-21 18:36:49 +00:00
|
|
|
if (action.report_type == 'qweb-pdf') {
|
|
|
|
(wkhtmltopdf_state = wkhtmltopdf_state || openerp.session.rpc('/report/check_wkhtmltopdf')).then(function (presence) {
|
|
|
|
// Fallback of qweb-pdf if wkhtmltopdf is not installed
|
|
|
|
if (presence == 'install' && action.report_type == 'qweb-pdf') {
|
|
|
|
self.do_notify(_t('Report'), _t('Unable to find Wkhtmltopdf on this \
|
|
|
|
system. The report will be shown in html.<br><br><a href="http://wkhtmltopdf.org/" target="_blank">\
|
|
|
|
wkhtmltopdf.org</a>'), true);
|
|
|
|
window.open(report_url.substring(12), '_blank', 'height=768,width=1024');
|
|
|
|
instance.web.unblockUI();
|
|
|
|
} else {
|
|
|
|
if (presence == 'upgrade') {
|
|
|
|
self.do_notify(_t('Report'), _t('You should upgrade your version of\
|
|
|
|
Wkhtmltopdf to at least 0.12.0 in order to get a correct display of headers and footers as well as\
|
|
|
|
support for table-breaking between pages.<br><br><a href="http://wkhtmltopdf.org/" \
|
|
|
|
target="_blank">wkhtmltopdf.org</a>'), true);
|
|
|
|
}
|
|
|
|
self.session.get_file({
|
|
|
|
url: '/report/download',
|
|
|
|
data: {data: JSON.stringify(response)},
|
|
|
|
complete: openerp.web.unblockUI,
|
|
|
|
error: c.rpc_error.bind(c)
|
|
|
|
});
|
2014-02-27 15:40:46 +00:00
|
|
|
}
|
2014-03-21 18:36:49 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self.session.get_file({
|
|
|
|
url: '/report/download',
|
|
|
|
data: {data: JSON.stringify(response)},
|
|
|
|
complete: openerp.web.unblockUI,
|
|
|
|
error: c.rpc_error.bind(c)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-02-18 10:49:59 +00:00
|
|
|
} else {
|
|
|
|
return self._super(action, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|