mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
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:
committed by
Sylvain GARANCHER
parent
77d817af25
commit
83170107a8
@@ -35,6 +35,7 @@
|
|||||||
'security/security.xml',
|
'security/security.xml',
|
||||||
'printing_data.xml',
|
'printing_data.xml',
|
||||||
'printing_view.xml',
|
'printing_view.xml',
|
||||||
|
'base_report_to_printer.xml',
|
||||||
'wizard/update_printers.xml',
|
'wizard/update_printers.xml',
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
|
|||||||
11
base_report_to_printer/base_report_to_printer.xml
Normal file
11
base_report_to_printer/base_report_to_printer.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
<template id="assets_backend" name="base_report_to_printer assets" inherit_id="report.assets_backend">
|
||||||
|
<xpath expr="." position="inside">
|
||||||
|
<script type="text/javascript" src="/base_report_to_printer/static/src/js/qwebactionmanager.js"></script>
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
|
</data>
|
||||||
|
</openerp>
|
||||||
|
|
||||||
@@ -52,6 +52,23 @@ class ReportXml(models.Model):
|
|||||||
'user basis'
|
'user basis'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def print_action_for_report_name(self, report_name):
|
||||||
|
""" Returns if the action is a direct print or pdf
|
||||||
|
|
||||||
|
Called from js
|
||||||
|
"""
|
||||||
|
report_obj = self.env['report']
|
||||||
|
report = report_obj._get_report_from_name(report_name)
|
||||||
|
if not report:
|
||||||
|
return {}
|
||||||
|
result = report.behaviour()[report.id]
|
||||||
|
serializable_result = {
|
||||||
|
'action': result['action'],
|
||||||
|
'printer_name': result['printer'].name,
|
||||||
|
}
|
||||||
|
return serializable_result
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def behaviour(self):
|
def behaviour(self):
|
||||||
result = {}
|
result = {}
|
||||||
|
|||||||
@@ -25,15 +25,30 @@ from openerp import models
|
|||||||
class Report(models.Model):
|
class Report(models.Model):
|
||||||
_inherit = 'report'
|
_inherit = 'report'
|
||||||
|
|
||||||
def get_pdf(self, cr, uid, ids, report_name, html=None,
|
def print_document(self, cr, uid, ids, report_name, html=None,
|
||||||
data=None, context=None):
|
data=None, context=None):
|
||||||
result = super(Report, self).get_pdf(cr, uid, ids, report_name,
|
""" Print a document, do not return the document file """
|
||||||
|
document = super(Report, self).get_pdf(cr, uid, ids, report_name,
|
||||||
html=html, data=data,
|
html=html, data=data,
|
||||||
context=context)
|
context=context)
|
||||||
report = self._get_report_from_name(cr, uid, report_name)
|
report = self._get_report_from_name(cr, uid, report_name)
|
||||||
data = report.behaviour()[report.id]
|
behaviour = report.behaviour()[report.id]
|
||||||
action = data['action']
|
printer = behaviour['printer']
|
||||||
printer = data['printer']
|
return printer.print_document(report, document, report.report_type)
|
||||||
if action != 'client' and result:
|
|
||||||
printer.print_document(report, result, report.report_type)
|
def get_pdf(self, cr, uid, ids, report_name, html=None,
|
||||||
return result
|
data=None, context=None):
|
||||||
|
""" Generate a PDF and returns it.
|
||||||
|
|
||||||
|
If the action configured on the report is server, it prints the
|
||||||
|
generated document as well.
|
||||||
|
"""
|
||||||
|
document = super(Report, self).get_pdf(cr, uid, ids, report_name,
|
||||||
|
html=html, data=data,
|
||||||
|
context=context)
|
||||||
|
report = self._get_report_from_name(cr, uid, report_name)
|
||||||
|
behaviour = report.behaviour()[report.id]
|
||||||
|
if behaviour['action'] == 'server' and document:
|
||||||
|
printer = behaviour['printer']
|
||||||
|
printer.print_document(report, document, report.report_type)
|
||||||
|
return document
|
||||||
|
|||||||
43
base_report_to_printer/static/src/js/qwebactionmanager.js
Normal file
43
base_report_to_printer/static/src/js/qwebactionmanager.js
Normal 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Reference in New Issue
Block a user