Merge pull-request #25 from nbessi:fix_mro_issue

Compatibility fix for report with custom parser

By calling super.get_pdf in print_document we can encounter trouble with MRO resolution
that prevent custom report parser (e.g. override of get_pdf) to be called.

The fix consist of not calling super and prevent multiple call to 'printer.print_document'
This commit is contained in:
Guewen Baconnier
2015-03-20 16:50:40 +01:00

View File

@@ -28,9 +28,12 @@ class Report(models.Model):
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)
if context is None:
context = self.pool['res.users'].context_get(cr, uid)
local_context = context.copy()
local_context['must_skip_send_to_printer'] = True
document = self.get_pdf(cr, uid, ids, report_name,
html=html, data=data, context=local_context)
report = self._get_report_from_name(cr, uid, report_name)
behaviour = report.behaviour()[report.id]
printer = behaviour['printer']
@@ -40,6 +43,19 @@ class Report(models.Model):
)
return printer.print_document(report, document, report.report_type)
def _can_print_report(self, cr, uid, ids, behaviour, printer, document,
context=None):
"""Predicate that decide if report can be sent to printer
If you want to prevent `get_pdf` to send report you can set
the `must_skip_send_to_printer` key to True in the context
"""
if context is not None and context.get('must_skip_send_to_printer'):
return False
if behaviour['action'] == 'server' and printer and document:
return True
return False
def get_pdf(self, cr, uid, ids, report_name, html=None,
data=None, context=None):
""" Generate a PDF and returns it.
@@ -53,6 +69,9 @@ class Report(models.Model):
report = self._get_report_from_name(cr, uid, report_name)
behaviour = report.behaviour()[report.id]
printer = behaviour['printer']
if behaviour['action'] == 'server' and printer and document:
can_print_report = self._can_print_report(cr, uid, ids,
behaviour, printer, document,
context=context)
if can_print_report:
printer.print_document(report, document, report.report_type)
return document