[FIX] Fixed the print_document method of report

The new API migration was made to @api.multi because of the "cr, uid,
ids" signature, but "ids" was the ids of the records to print here, not
the report's ids.
Also, the new API version of "get_pdf" get directly the ids of the
records to print in the standard module, not a recordset.
This commit is contained in:
Sylvain GARANCHER
2017-02-23 18:03:55 +01:00
parent 20284f72a5
commit 7422e99933
2 changed files with 68 additions and 22 deletions

View File

@@ -8,28 +8,19 @@ from openerp import models, exceptions, _, api
class Report(models.Model):
_inherit = 'report'
@api.multi
def print_document(self, report_name, html=None, data=None):
@api.model
def print_document(self, record_ids, report_name, html=None, data=None):
""" Print a document, do not return the document file """
res = []
context = self.env.context
if context is None:
context = self.env['res.users'].context_get()
local_context = context.copy()
local_context['must_skip_send_to_printer'] = True
for rec_id in self.with_context(local_context):
document = rec_id.get_pdf(report_name, html=html, data=data)
report = self._get_report_from_name(report_name)
behaviour = report.behaviour()[report.id]
printer = behaviour['printer']
if not printer:
raise exceptions.Warning(
_('No printer configured to print this report.')
)
res.append(
printer.print_document(report, document, report.report_type)
document = self.with_context(must_skip_send_to_printer=True).get_pdf(
record_ids, report_name, html=html, data=data)
report = self._get_report_from_name(report_name)
behaviour = report.behaviour()[report.id]
printer = behaviour['printer']
if not printer:
raise exceptions.Warning(
_('No printer configured to print this report.')
)
return all(res)
return printer.print_document(report, document, report.report_type)
@api.multi
def _can_print_report(self, behaviour, printer, document):
@@ -66,7 +57,7 @@ class Report(models.Model):
return document
@api.v8
def get_pdf(self, records, report_name, html=None, data=None):
def get_pdf(self, docids, report_name, html=None, data=None):
return self._model.get_pdf(self._cr, self._uid,
records.ids, report_name,
docids, report_name,
html=html, data=data, context=self._context)