1 openerp.report = function(instance) {
4 var trigger_download = function(session, response, c) {
6 url: '/report/download',
7 data: {data: JSON.stringify(response)},
8 complete: openerp.web.unblockUI,
9 error: c.rpc_error.bind(c)
12 var show_pdf = function(session, response, c, options, self) {
13 response.push("pdf_viewer")
15 url: '/report/download',
16 data: {data: JSON.stringify(response)},
18 openerp.web.unblockUI();
25 error: c.rpc_error.bind(c)
29 instance.web.ActionManager = instance.web.ActionManager.extend({
30 ir_actions_report_xml: function(action, options) {
32 instance.web.blockUI();
33 action = _.clone(action);
37 if ('report_type' in action && (action.report_type == 'qweb-html' || action.report_type == 'qweb-pdf' || action.report_type == 'controller')) {
39 switch (action.report_type) {
41 report_url = '/report/html/' + action.report_name;
44 report_url = '/report/pdf/' + action.report_name;
47 report_url = action.report_file;
50 report_url = '/report/html/' + action.report_name;
54 // generic report: no query string
55 // particular: query string of action.data.form and context
56 if (!('data' in action) || !(action.data)) {
57 if ('active_ids' in action.context) {
58 report_url += "/" + action.context.active_ids.join(',');
61 report_url += "?options=" + encodeURIComponent(JSON.stringify(action.data));
62 report_url += "&context=" + encodeURIComponent(JSON.stringify(action.context));
65 var response = new Array();
66 response[0] = report_url;
67 response[1] = action.report_type;
68 var c = openerp.webclient.crashmanager;
70 if (action.report_type == 'qweb-html') {
71 window.open(report_url, '_blank', 'scrollbars=1,height=900,width=1280');
72 instance.web.unblockUI();
73 } else if (action.report_type === 'qweb-pdf') {
74 // Trigger the download of the pdf/controller report
75 (wkhtmltopdf_state = wkhtmltopdf_state || openerp.session.rpc('/report/check_wkhtmltopdf')).then(function (presence) {
76 // Fallback on html if wkhtmltopdf is not installed or if OpenERP is started with one worker
77 if (presence === 'install') {
78 self.do_notify(_t('Report'), _t('Unable to find Wkhtmltopdf on this \
79 system. The report will be shown in html.<br><br><a href="http://wkhtmltopdf.org/" target="_blank">\
80 wkhtmltopdf.org</a>'), true);
81 report_url = report_url.substring(12)
82 window.open('/report/html/' + report_url, '_blank', 'height=768,width=1024');
83 instance.web.unblockUI();
85 } else if (presence === 'workers') {
86 self.do_notify(_t('Report'), _t('You need to start OpenERP with at least two \
87 workers to print a pdf version of the reports.'), true);
88 report_url = report_url.substring(12)
89 window.open('/report/html/' + report_url, '_blank', 'height=768,width=1024');
90 instance.web.unblockUI();
92 } else if (presence === 'upgrade') {
93 self.do_notify(_t('Report'), _t('You should upgrade your version of\
94 Wkhtmltopdf to at least 0.12.0 in order to get a correct display of headers and footers as well as\
95 support for table-breaking between pages.<br><br><a href="http://wkhtmltopdf.org/" \
96 target="_blank">wkhtmltopdf.org</a>'), true);
98 if(action.hasOwnProperty('pdf_viewer')){
99 return show_pdf(self.session, response, c, options, self);
102 return trigger_download(self.session, response, c );
105 } else if (action.report_type === 'controller') {
106 return trigger_download(self.session, response, c);
109 return self._super(action, options);