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:
Nicolas Bessi
2015-01-30 14:10:57 +01:00
committed by hda
parent edbd401309
commit 28d2db83a2

View File

@@ -25,12 +25,30 @@ from openerp import models, exceptions, _
class Report(models.Model): class Report(models.Model):
_inherit = 'report' _inherit = 'report'
def _can_send_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_sent_to_printer` key to True in the context
"""
if context is None:
context = self.pool['res.users'].context_get(cr, uid)
if context.get('must_skip_sent_to_printer'):
return False
if behaviour['action'] == 'server' and printer and document:
return True
return False
def print_document(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):
""" Print a document, do not return the document file """ """ Print a document, do not return the document file """
document = super(Report, self).get_pdf(cr, uid, ids, report_name, if context is None:
html=html, data=data, context = self.pool['res.users'].context_get(cr, uid)
context=context) local_context = dict(context)
local_context['must_skip_sent_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) report = self._get_report_from_name(cr, uid, report_name)
behaviour = report.behaviour()[report.id] behaviour = report.behaviour()[report.id]
printer = behaviour['printer'] printer = behaviour['printer']
@@ -47,12 +65,18 @@ class Report(models.Model):
If the action configured on the report is server, it prints the If the action configured on the report is server, it prints the
generated document as well. generated document as well.
""" """
if context is None:
context = self.pool['res.users'].context_get(cr, uid)
document = super(Report, self).get_pdf(cr, uid, ids, report_name, 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)
behaviour = report.behaviour()[report.id] behaviour = report.behaviour()[report.id]
printer = behaviour['printer'] printer = behaviour['printer']
if behaviour['action'] == 'server' and printer and document: can_send_report = self._can_send_report(cr, uid, ids,
behaviour, printer, document,
context=context)
if can_send_report:
printer.print_document(report, document, report.report_type) printer.print_document(report, document, report.report_type)
context['must_skip_sent_to_printer'] = True
return document return document