1
# -*- coding: utf-8 -*-
2
# Copyright (c) 2014 Camptocamp SA
3
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
5
from odoo import models, exceptions, _, api
8
class Report(models.Model):
12
def print_document(self, record_ids, report_name, html=None, data=None):
13
""" Print a document, do not return the document file """
14
document = self.with_context(must_skip_send_to_printer=True).get_pdf(
15
record_ids, report_name, html=html, data=data)
16
report = self._get_report_from_name(report_name)
17
behaviour = report.behaviour()[report.id]
18
printer = behaviour['printer']
20
raise exceptions.Warning(
21
_('No printer configured to print this report.')
23
return printer.print_document(report, document, report.report_type)
26
def _can_print_report(self, behaviour, printer, document):
27
"""Predicate that decide if report can be sent to printer
29
If you want to prevent `get_pdf` to send report you can set
30
the `must_skip_send_to_printer` key to True in the context
32
if self.env.context.get('must_skip_send_to_printer'):
34
if behaviour['action'] == 'server' and printer and document:
39
def get_pdf(self, docids, report_name, html=None, data=None):
40
""" Generate a PDF and returns it.
42
If the action configured on the report is server, it prints the
43
generated document as well.
45
document = super(Report, self).get_pdf(
46
docids, report_name, html=html, data=data)
48
report = self._get_report_from_name(report_name)
49
behaviour = report.behaviour()[report.id]
50
printer = behaviour['printer']
51
can_print_report = self._can_print_report(behaviour, printer, document)
54
printer.print_document(report, document, report.report_type)