mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[10.0][MIG] base_report_to_printer (#68)
* Set api.multi for action called as `object` on view * Merge syleam printers module into base_report_to_printer (#60) * [IMP] Updated unit tests * [FIX] Fixed renamed attributes * [FIX] Remove deleted fields * [IMP] Add printing.server and printing.job models * [IMP] Allow to cancel all jobs, enable, and disable printers * [IMP] Split the cups part of print_document into a new print_file method * [IMP] Updated cron job to run the action_update_jobs method * [ADD] Add a migration script to create a printing server from configuration * [MIG] Migrate base_report_to_printer to v10.0 Removed deprecated methods on printing.printer (replaced by methods on printing.server) * [IMP] Add wkhtmltopdf in travis configuration file * [FIX] base_report_to_printer: Fix Update Job Cron * Fix API issue with Update Job Cron ** Forward Port from 9.0 * [FIX] Fixed the res.users view The string attribute should not be used as a selector, because it is translatable. * [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. * [FIX] UI is now (un)blocked only when using qweb-pdf reports in standard addons
This commit is contained in:
committed by
trisdoan
parent
21b19339ae
commit
cbdf1b13a7
@@ -2,34 +2,25 @@
|
||||
# Copyright (c) 2014 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import models, exceptions, _, api
|
||||
from odoo 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):
|
||||
@@ -44,29 +35,22 @@ class Report(models.Model):
|
||||
return True
|
||||
return False
|
||||
|
||||
@api.v7
|
||||
def get_pdf(self, cr, uid, ids, report_name, html=None,
|
||||
data=None, context=None):
|
||||
@api.model
|
||||
def get_pdf(self, docids, report_name, html=None, data=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)
|
||||
document = super(Report, self).get_pdf(
|
||||
docids, report_name, html=html, data=data)
|
||||
|
||||
report = self._get_report_from_name(report_name)
|
||||
behaviour = report.behaviour()[report.id]
|
||||
printer = behaviour['printer']
|
||||
can_print_report = self._can_print_report(cr, uid, ids,
|
||||
behaviour, printer, document,
|
||||
context=context)
|
||||
can_print_report = self._can_print_report(behaviour, printer, document)
|
||||
|
||||
if can_print_report:
|
||||
printer.print_document(report, document, report.report_type)
|
||||
return document
|
||||
|
||||
@api.v8
|
||||
def get_pdf(self, records, report_name, html=None, data=None):
|
||||
return self._model.get_pdf(self._cr, self._uid,
|
||||
records.ids, report_name,
|
||||
html=html, data=data, context=self._context)
|
||||
return document
|
||||
|
||||
Reference in New Issue
Block a user