Do no longer returns a PDF when a report is printed

Instead, a notification is displayed to the user.
When report.get_pdf() is called on a report that must be printer,
it will print the report *and* returns the pdf, thus code that
calls directly report.get_pdf() will print the pdf on the printer
as expected.

Fixes #16
This commit is contained in:
Guewen Baconnier
2015-01-21 14:56:23 +01:00
committed by Carlos Roca
parent 74ce12bf3f
commit 79549a7bf4
8 changed files with 225 additions and 71 deletions

View File

@@ -0,0 +1,43 @@
openerp.base_report_to_printer = function(instance) {
instance.web.ActionManager.include({
ir_actions_report_xml: function(action, options) {
instance.web.blockUI();
action = _.clone(action);
var _t = instance.web._t;
var self = this;
var _super = this._super;
if ('report_type' in action && action.report_type === 'qweb-pdf') {
new instance.web.Model('ir.actions.report.xml')
.call('print_action_for_report_name', [action.report_name])
.then(function(print_action){
if (print_action && print_action['action'] === 'server') {
instance.web.unblockUI();
new instance.web.Model('report')
.call('print_document',
[action.context.active_ids,
action.report_name,
],
{data: action.data || {},
context: action.context || {},
})
.then(function(result){
self.do_notify(_t('Report'),
_t('Document sent to the printer ') + print_action.printer_name);
}).fail(function() {
self.do_notify(_t('Report'),
_t('Error when sending the document to the printer ') + print_action.printer_name);
});
} else {
return _super.apply(self, [action, options]);
}
});
} else {
return _super.apply(self, [action, options]);
}
}
});
};