Implements the print on the new 'report' model

This commit is contained in:
Guewen Baconnier
2014-11-17 10:41:35 +01:00
parent 838c6693f5
commit aa22f62bbb
5 changed files with 74 additions and 39 deletions

View File

@@ -21,13 +21,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import base64
import logging
import os
from tempfile import mkstemp
import cups
from openerp import models, fields, api
@@ -58,39 +52,6 @@ class ReportXml(models.Model):
'user basis'
)
@api.multi
def set_print_options(self, format):
""" Hook to set print options """
options = {}
if format == 'raw':
options['raw'] = True
return options
@api.multi
def print_direct(self, result, format, printer):
self.ensure_one()
fd, file_name = mkstemp()
try:
os.write(fd, base64.decodestring(result))
finally:
os.close(fd)
printer_system_name = ''
if printer:
if isinstance(printer, (basestring)):
printer_system_name = printer
else:
printer_system_name = printer.system_name
connection = cups.Connection()
options = self.set_print_options(format)
connection.printFile(printer_system_name,
file_name,
file_name,
options=options)
_logger.info("Printing job: '%s'" % file_name)
return True
@api.multi
def behaviour(self):
result = {}