From 890d0d64eced0045eaeabce7e36d6496abaf872d Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Mon, 30 Sep 2013 11:50:14 +0200 Subject: [PATCH] [IMP] base_report_to_printer - retab and clean extra spaces --- base_report_to_printer/__openerp__.py | 14 +++--- base_report_to_printer/printing.py | 45 ++++++++++--------- .../wizard/update_printers.py | 8 ++-- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/base_report_to_printer/__openerp__.py b/base_report_to_printer/__openerp__.py index 0270a2e..6aa30a9 100644 --- a/base_report_to_printer/__openerp__.py +++ b/base_report_to_printer/__openerp__.py @@ -27,13 +27,13 @@ '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. Before you can use this module: - 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 - 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. - Then goto the user profile and set the users printing action and default printer. - """, + 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 + 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. + Then goto the user profile and set the users printing action and default printer. + """, 'author': 'Agile Business Group & Domsense, Pegueroles SCP, NaN', 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', diff --git a/base_report_to_printer/printing.py b/base_report_to_printer/printing.py index a4a9710..6cb5bf3 100644 --- a/base_report_to_printer/printing.py +++ b/base_report_to_printer/printing.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # Copyright (c) 2007 Ferran Pegueroles # Copyright (c) 2009 Albert Cervera i Areny # Copyright (C) 2011 Agile Business Group sagl () @@ -34,10 +34,10 @@ from threading import Lock import netsvc import tools -import time +import time from osv import fields from osv import osv -import pooler +import pooler import tools from tools.translate import _ from base_calendar import base_calendar @@ -60,13 +60,14 @@ class printing_printer(osv.osv): 'model': fields.char('Model', size=500, readonly=True), 'location': fields.char('Location', size=500, readonly=True), 'uri': fields.char('URI', size=500, readonly=True), - } + } + _order = "name" - + _defaults = { 'default': lambda *a: False, 'status': lambda *a: 'unknown', - } + } def __init__(self, pool, cr): super(printing_printer, self).__init__(pool, cr) @@ -90,7 +91,7 @@ class printing_printer(osv.osv): 4 : 'printing', 5 : 'error' } - + try: # Skip update to avoid the thread being created again 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, ids[0], {'default':True}, context) return True - + def get_default(self,cr,uid,context): printer_ids = self.search(cr, uid,[('default','=',True)]) if printer_ids: @@ -194,7 +195,7 @@ def _available_action_types(self, cr, uid, context=None): ('server',_('Send to Printer')), ('client',_('Send to Client')), ('user_default',_("Use user's defaults")), - ] + ] class printing_action(osv.osv): _name = 'printing.action' @@ -203,10 +204,10 @@ class printing_action(osv.osv): _columns = { 'name': fields.char('Name', size=256, required=True), 'type': fields.selection(_available_action_types, 'Type', required=True), - } + } printing_action() -# +# # Users # @@ -222,13 +223,13 @@ class res_users(osv.osv): _columns = { 'printing_action': fields.selection(_user_available_action_types, 'Printing Action'), 'printing_printer_id': fields.many2one('printing.printer', 'Default Printer'), - } + } res_users() # # Reports -# +# class report_xml(osv.osv): @@ -246,10 +247,10 @@ class report_xml(osv.osv): printer_system_name = printer.system_name if format == 'raw': # -l is the same as -o raw - cmd = "lpr -l -P %s %s" % (printer_system_name,file_name) - #cmd = "lp -d %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) 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) logger = logging.getLogger('base_report_to_printer') logger.info("Printing job : '%s'" % cmd) @@ -266,10 +267,10 @@ class report_xml(osv.osv): string='Action', view_load=True, method=True, - ), + ), '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'), - } + } def behaviour(self, cr, uid, ids, context=None): if context is None: @@ -311,7 +312,7 @@ class report_xml(osv.osv): result[report.id] = { 'action': action, 'printer': printer, - } + } return result @@ -325,7 +326,7 @@ class report_xml_action(osv.osv): 'user_id': fields.many2one('res.users', 'User', required=True, ondelete='cascade'), 'action': fields.selection(_available_action_types, 'Action', required=True), 'printer_id': fields.many2one('printing.printer', 'Printer'), - } + } def behaviour(self, cr, uid, report_id, context=None): if context is None: @@ -338,7 +339,7 @@ class report_xml_action(osv.osv): return { 'action': action.action, 'printer': action.printer_id.system_name, - } + } report_xml_action() 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']), self._reports[report_id]['format'], printer) raise osv.except_osv(_('Printing...'), _('Document sent to printer %s') % (printer,)) - + except: cr.rollback() raise diff --git a/base_report_to_printer/wizard/update_printers.py b/base_report_to_printer/wizard/update_printers.py index abbe04e..41754f8 100644 --- a/base_report_to_printer/wizard/update_printers.py +++ b/base_report_to_printer/wizard/update_printers.py @@ -35,7 +35,7 @@ class printing_printer_update_wizard(osv.osv_memory): _name = "printing.printer.update.wizard" _columns = { - } + } def action_cancel(self, cr, uid, ids, context=None): 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) for printer in self.pool.get('printing.printer').browse(cr, uid, ids, context): del printers[printer.system_name] - + for name in printers: printer = printers[name] 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), 'location': printer.get('printer-location', False), 'uri': printer.get('device-uri', False), - }, context) + }, context) return { 'name': 'Printers', @@ -69,7 +69,7 @@ class printing_printer_update_wizard(osv.osv_memory): 'res_model': 'printing.printer', 'type': 'ir.actions.act_window', 'target': 'current', - } + } printing_printer_update_wizard()