[IMP] base_report_to_printer - retab and clean extra spaces

This commit is contained in:
Yannick Vaucher
2013-09-30 11:50:14 +02:00
parent 96376b10e8
commit 890d0d64ec
3 changed files with 34 additions and 33 deletions

View File

@@ -27,13 +27,13 @@
'category': 'Generic Modules/Base', 'category': 'Generic Modules/Base',
'description': """This module allows users to send reports to a printer attached to the server. Settings can be configured globaly, per user, per report and per user and report. 'description': """This module allows users to send reports to a printer attached to the server. Settings can be configured globaly, per user, per report and per user and report.
Before you can use this module: Before you can use this module:
You must have lpr installed for this module to work as-is. You must have lpr installed for this module to work as-is.
To install lpr on ubuntu enter this command at the CLI - sudo apt-get install cups-bsd To install lpr on ubuntu enter this command at the CLI - sudo apt-get install cups-bsd
type ls | lpr at the command prompt to confirm your server can print type ls | lpr at the command prompt to confirm your server can print
After installing enable the "Printing / Print Operator" option under access rights to give users the ability to view the print menu. After installing enable the "Printing / Print Operator" option under access rights to give users the ability to view the print menu.
Then goto the user profile and set the users printing action and default printer. Then goto the user profile and set the users printing action and default printer.
""", """,
'author': 'Agile Business Group & Domsense, Pegueroles SCP, NaN', 'author': 'Agile Business Group & Domsense, Pegueroles SCP, NaN',
'website': 'http://www.agilebg.com', 'website': 'http://www.agilebg.com',
'license': 'AGPL-3', 'license': 'AGPL-3',

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com> # Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# 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>)
@@ -34,10 +34,10 @@ from threading import Lock
import netsvc import netsvc
import tools import tools
import time import time
from osv import fields from osv import fields
from osv import osv from osv import osv
import pooler import pooler
import tools import tools
from tools.translate import _ from tools.translate import _
from base_calendar import base_calendar from base_calendar import base_calendar
@@ -60,13 +60,14 @@ class printing_printer(osv.osv):
'model': fields.char('Model', size=500, readonly=True), 'model': fields.char('Model', size=500, readonly=True),
'location': fields.char('Location', size=500, readonly=True), 'location': fields.char('Location', size=500, readonly=True),
'uri': fields.char('URI', size=500, readonly=True), 'uri': fields.char('URI', size=500, readonly=True),
} }
_order = "name" _order = "name"
_defaults = { _defaults = {
'default': lambda *a: False, 'default': lambda *a: False,
'status': lambda *a: 'unknown', 'status': lambda *a: 'unknown',
} }
def __init__(self, pool, cr): def __init__(self, pool, cr):
super(printing_printer, self).__init__(pool, cr) super(printing_printer, self).__init__(pool, cr)
@@ -90,7 +91,7 @@ class printing_printer(osv.osv):
4 : 'printing', 4 : 'printing',
5 : 'error' 5 : 'error'
} }
try: try:
# Skip update to avoid the thread being created again # Skip update to avoid the thread being created again
ctx = context.copy() ctx = context.copy()
@@ -174,7 +175,7 @@ class printing_printer(osv.osv):
self.write(cr, uid, default_ids, {'default':False}, context) self.write(cr, uid, default_ids, {'default':False}, context)
self.write(cr, uid, ids[0], {'default':True}, context) self.write(cr, uid, ids[0], {'default':True}, context)
return True return True
def get_default(self,cr,uid,context): def get_default(self,cr,uid,context):
printer_ids = self.search(cr, uid,[('default','=',True)]) printer_ids = self.search(cr, uid,[('default','=',True)])
if printer_ids: if printer_ids:
@@ -194,7 +195,7 @@ def _available_action_types(self, cr, uid, context=None):
('server',_('Send to Printer')), ('server',_('Send to Printer')),
('client',_('Send to Client')), ('client',_('Send to Client')),
('user_default',_("Use user's defaults")), ('user_default',_("Use user's defaults")),
] ]
class printing_action(osv.osv): class printing_action(osv.osv):
_name = 'printing.action' _name = 'printing.action'
@@ -203,10 +204,10 @@ class printing_action(osv.osv):
_columns = { _columns = {
'name': fields.char('Name', size=256, required=True), 'name': fields.char('Name', size=256, required=True),
'type': fields.selection(_available_action_types, 'Type', required=True), 'type': fields.selection(_available_action_types, 'Type', required=True),
} }
printing_action() printing_action()
# #
# Users # Users
# #
@@ -222,13 +223,13 @@ class res_users(osv.osv):
_columns = { _columns = {
'printing_action': fields.selection(_user_available_action_types, 'Printing Action'), 'printing_action': fields.selection(_user_available_action_types, 'Printing Action'),
'printing_printer_id': fields.many2one('printing.printer', 'Default Printer'), 'printing_printer_id': fields.many2one('printing.printer', 'Default Printer'),
} }
res_users() res_users()
# #
# Reports # Reports
# #
class report_xml(osv.osv): class report_xml(osv.osv):
@@ -246,10 +247,10 @@ class report_xml(osv.osv):
printer_system_name = printer.system_name printer_system_name = printer.system_name
if format == 'raw': if format == 'raw':
# -l is the same as -o raw # -l is the same as -o raw
cmd = "lpr -l -P %s %s" % (printer_system_name,file_name) cmd = "lpr -l -P %s %s" % (printer_system_name,file_name)
#cmd = "lp -d %s %s" % (printer_system_name,file_name) #cmd = "lp -d %s %s" % (printer_system_name,file_name)
else: else:
cmd = "lpr -P %s %s" % (printer_system_name,file_name) cmd = "lpr -P %s %s" % (printer_system_name,file_name)
#cmd = "lp -d %s %s" % (printer_system_name,file_name) #cmd = "lp -d %s %s" % (printer_system_name,file_name)
logger = logging.getLogger('base_report_to_printer') logger = logging.getLogger('base_report_to_printer')
logger.info("Printing job : '%s'" % cmd) logger.info("Printing job : '%s'" % cmd)
@@ -266,10 +267,10 @@ class report_xml(osv.osv):
string='Action', string='Action',
view_load=True, view_load=True,
method=True, method=True,
), ),
'printing_printer_id': fields.many2one('printing.printer', 'Printer'), 'printing_printer_id': fields.many2one('printing.printer', 'Printer'),
'printing_action_ids': fields.one2many('printing.report.xml.action', 'report_id', 'Actions', help='This field allows configuring action and printer on a per user basis'), 'printing_action_ids': fields.one2many('printing.report.xml.action', 'report_id', 'Actions', help='This field allows configuring action and printer on a per user basis'),
} }
def behaviour(self, cr, uid, ids, context=None): def behaviour(self, cr, uid, ids, context=None):
if context is None: if context is None:
@@ -311,7 +312,7 @@ class report_xml(osv.osv):
result[report.id] = { result[report.id] = {
'action': action, 'action': action,
'printer': printer, 'printer': printer,
} }
return result return result
@@ -325,7 +326,7 @@ class report_xml_action(osv.osv):
'user_id': fields.many2one('res.users', 'User', required=True, ondelete='cascade'), 'user_id': fields.many2one('res.users', 'User', required=True, ondelete='cascade'),
'action': fields.selection(_available_action_types, 'Action', required=True), 'action': fields.selection(_available_action_types, 'Action', required=True),
'printer_id': fields.many2one('printing.printer', 'Printer'), 'printer_id': fields.many2one('printing.printer', 'Printer'),
} }
def behaviour(self, cr, uid, report_id, context=None): def behaviour(self, cr, uid, report_id, context=None):
if context is None: if context is None:
@@ -338,7 +339,7 @@ class report_xml_action(osv.osv):
return { return {
'action': action.action, 'action': action.action,
'printer': action.printer_id.system_name, 'printer': action.printer_id.system_name,
} }
report_xml_action() report_xml_action()
class virtual_report_spool(base_calendar.virtual_report_spool): class virtual_report_spool(base_calendar.virtual_report_spool):
@@ -368,7 +369,7 @@ class virtual_report_spool(base_calendar.virtual_report_spool):
report_obj.print_direct(cr, uid, base64.encodestring(self._reports[report_id]['result']), report_obj.print_direct(cr, uid, base64.encodestring(self._reports[report_id]['result']),
self._reports[report_id]['format'], printer) self._reports[report_id]['format'], printer)
raise osv.except_osv(_('Printing...'), _('Document sent to printer %s') % (printer,)) raise osv.except_osv(_('Printing...'), _('Document sent to printer %s') % (printer,))
except: except:
cr.rollback() cr.rollback()
raise raise

View File

@@ -35,7 +35,7 @@ class printing_printer_update_wizard(osv.osv_memory):
_name = "printing.printer.update.wizard" _name = "printing.printer.update.wizard"
_columns = { _columns = {
} }
def action_cancel(self, cr, uid, ids, context=None): def action_cancel(self, cr, uid, ids, context=None):
return {} return {}
@@ -51,7 +51,7 @@ class printing_printer_update_wizard(osv.osv_memory):
ids = self.pool.get('printing.printer').search(cr, uid, [('system_name','in',printers.keys())], context=context) ids = self.pool.get('printing.printer').search(cr, uid, [('system_name','in',printers.keys())], context=context)
for printer in self.pool.get('printing.printer').browse(cr, uid, ids, context): for printer in self.pool.get('printing.printer').browse(cr, uid, ids, context):
del printers[printer.system_name] del printers[printer.system_name]
for name in printers: for name in printers:
printer = printers[name] printer = printers[name]
self.pool.get('printing.printer').create(cr, uid, { self.pool.get('printing.printer').create(cr, uid, {
@@ -60,7 +60,7 @@ class printing_printer_update_wizard(osv.osv_memory):
'model': printer.get('printer-make-and-model', False), 'model': printer.get('printer-make-and-model', False),
'location': printer.get('printer-location', False), 'location': printer.get('printer-location', False),
'uri': printer.get('device-uri', False), 'uri': printer.get('device-uri', False),
}, context) }, context)
return { return {
'name': 'Printers', 'name': 'Printers',
@@ -69,7 +69,7 @@ class printing_printer_update_wizard(osv.osv_memory):
'res_model': 'printing.printer', 'res_model': 'printing.printer',
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'target': 'current', 'target': 'current',
} }
printing_printer_update_wizard() printing_printer_update_wizard()