Restore the print capability on deprecated reports

This commit is contained in:
Guewen Baconnier
2014-11-17 11:41:46 +01:00
committed by Sylvain GARANCHER
parent 9c4ea8c10c
commit 3d89e22aeb

View File

@@ -5,8 +5,7 @@
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com> # Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) # Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) # Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013 Camptocamp (<http://www.camptocamp.com>) # Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# All Rights Reserved
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published # it under the terms of the GNU Affero General Public License as published
@@ -22,57 +21,65 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
# TODO check if we have to remove
# import base64
# from openerp import pooler import openerp
# from openerp.addons.base_calendar import base_calendar
from openerp.service.report import self_reports
original_exp_report = openerp.service.report.exp_report
# class virtual_report_spool(base_calendar.virtual_report_spool): def exp_report(db, uid, object, ids, datas=None, context=None):
""" Export Report """
# We can't use the named args because a monkey patch in 'calendar'
# doesn't use them and use a different name for 'datas'
res = original_exp_report(db, uid, object, ids, datas, context)
self_reports[res]['report_name'] = object
return res
# def exp_report(self, db, uid, object, ids, datas=None, context=None):
# res = super(virtual_report_spool, self).exp_report(db, uid, object, ids, datas, context)
# self._reports[res]['report_name'] = object
# return res
# def exp_report_get(self, db, uid, report_id): openerp.service.report.exp_report = exp_report
# cr = pooler.get_db(db).cursor()
# try:
# pool = pooler.get_pool(cr.dbname)
# # First of all load report defaults: name, action and printer
# report_obj = pool.get('ir.actions.report.xml')
# report = report_obj.search(
# cr, uid, [('report_name', '=', self._reports[report_id]['report_name'])])
# if report:
# report = report_obj.browse(cr, uid, report[0])
# data = report.behaviour()[report.id]
# action = data['action']
# printer = data['printer']
# if action != 'client':
# if (self._reports and self._reports.get(report_id, False)
# and self._reports[report_id].get('result', False)
# and self._reports[report_id].get('format', False)):
# report_obj.print_direct(
# cr, uid, report.id, base64.encodestring(self._reports[report_id]['result']),
# self._reports[report_id]['format'], printer)
# # FIXME "Warning" removed as it breaks the workflow
# # it would be interesting to have a dialog box to confirm if we really want to print
# # in this case it must be with a by pass parameter to allow massive impression
# # raise osv.except_osv(
# # _('Printing...'),
# # _('Document sent to printer %s') % (printer,))
# except: original_exp_report_get = openerp.service.report.exp_report_get
# cr.rollback()
# raise
# finally:
# cr.close()
# res = super(virtual_report_spool, self).exp_report_get(db, uid, report_id)
# return res
# virtual_report_spool() def exp_report_get(db, uid, report_id):
registry = openerp.registry(db)
cr = registry.cursor()
try:
# First of all load report defaults: name, action and printer
report_obj = registry['ir.actions.report.xml']
report_name = self_reports[report_id]['report_name']
report = report_obj.search(cr, uid,
[('report_name', '=', report_name)])
if report:
report = report_obj.browse(cr, uid, report[0])
data = report.behaviour()[report.id]
action = data['action']
printer = data['printer']
if action != 'client':
if (self_reports and self_reports.get(report_id)
and self_reports[report_id].get('result')
and self_reports[report_id].get('format')):
printer.print_document(self_reports[report_id]['result'],
self_reports[report_id]['format'])
# FIXME "Warning" removed as it breaks the workflow
# it would be interesting to have a dialog box to
# confirm if we really want to print in this case it
# must be with a by pass parameter to allow massive
# prints
# raise osv.except_osv(
# _('Printing...'),
# _('Document sent to printer %s') % (printer,))
# # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: except:
cr.rollback()
raise
finally:
cr.close()
return original_exp_report_get(db, uid, report_id)
openerp.service.report.exp_report_get = exp_report_get