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

@@ -19,21 +19,40 @@
#
##############################################################################
from openerp import models
from openerp import models, exceptions, _
class Report(models.Model):
_inherit = 'report'
def print_document(self, cr, uid, ids, report_name, html=None,
data=None, context=None):
""" Print a document, do not return the document file """
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]
printer = behaviour['printer']
if not printer:
raise exceptions.Warning(
_('No printer configured to print this report.')
)
return printer.print_document(report, document, report.report_type)
def get_pdf(self, cr, uid, ids, report_name, html=None,
data=None, context=None):
result = super(Report, self).get_pdf(cr, uid, ids, report_name,
html=html, data=data,
context=context)
""" 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)
data = report.behaviour()[report.id]
action = data['action']
printer = data['printer']
if action != 'client' and result:
printer.print_document(report, result, report.report_type)
return result
behaviour = report.behaviour()[report.id]
printer = behaviour['printer']
if behaviour['action'] == 'server' and printer and document:
printer.print_document(report, document, report.report_type)
return document