mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
Implements the print on the new 'report' model
This commit is contained in:
@@ -22,9 +22,11 @@
|
||||
#
|
||||
##############################################################################
|
||||
import logging
|
||||
import os
|
||||
|
||||
from contextlib import contextmanager
|
||||
from datetime import datetime
|
||||
from tempfile import mkstemp
|
||||
from threading import Thread
|
||||
|
||||
import cups
|
||||
@@ -221,6 +223,37 @@ class PrintingPrinter(models.Model):
|
||||
location = fields.Char(readonly=True)
|
||||
uri = fields.Char(readonly=True)
|
||||
|
||||
def print_options(self, format):
|
||||
""" Hook to set print options """
|
||||
options = {}
|
||||
if format == 'raw':
|
||||
options['raw'] = True
|
||||
return options
|
||||
|
||||
@api.multi
|
||||
def print_document(self, content, format):
|
||||
""" Print a file
|
||||
|
||||
Format could be pdf, qweb-pdf, raw, ...
|
||||
|
||||
"""
|
||||
self.ensure_one()
|
||||
fd, file_name = mkstemp()
|
||||
try:
|
||||
os.write(fd, content)
|
||||
finally:
|
||||
os.close(fd)
|
||||
connection = cups.Connection()
|
||||
|
||||
options = self.print_options(format)
|
||||
|
||||
connection.printFile(self.system_name,
|
||||
file_name,
|
||||
file_name,
|
||||
options=options)
|
||||
_logger.info("Printing job: '%s'" % file_name)
|
||||
return True
|
||||
|
||||
@api.model
|
||||
def start_printer_update(self):
|
||||
polling_obj = self.env['printing.printer.polling']
|
||||
|
||||
Reference in New Issue
Block a user