mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
fix flakes8
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
#
|
||||
##############################################################################
|
||||
import time
|
||||
import base64
|
||||
|
||||
import cups
|
||||
from threading import Thread
|
||||
@@ -32,25 +31,53 @@ from threading import Lock
|
||||
from openerp import pooler
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.tools.translate import _
|
||||
from openerp.addons.base_calendar import base_calendar
|
||||
|
||||
|
||||
#
|
||||
# Printers
|
||||
#
|
||||
class printing_printer(orm.Model):
|
||||
"""
|
||||
Printers
|
||||
"""
|
||||
_name = "printing.printer"
|
||||
_description = "Printer"
|
||||
|
||||
_columns = {
|
||||
'name' : fields.char('Name',size=64,required=True,select="1"),
|
||||
'system_name': fields.char('System Name',size=64,required=True,select="1"),
|
||||
'default':fields.boolean('Default Printer', readonly=True),
|
||||
'status': fields.selection([('unavailable','Unavailable'),('printing','Printing'),('unknown','Unknown'),('available','Available'),('error','Error'),('server-error','Server Error')], 'Status', required=True, readonly=True),
|
||||
'status_message': fields.char('Status Message', size=500, readonly=True),
|
||||
'model': fields.char('Model', size=500, readonly=True),
|
||||
'location': fields.char('Location', size=500, readonly=True),
|
||||
'uri': fields.char('URI', size=500, readonly=True),
|
||||
'name': fields.char(
|
||||
'Name',
|
||||
size=64,
|
||||
required=True,
|
||||
select="1"),
|
||||
'system_name': fields.char(
|
||||
'System Name',
|
||||
size=64,
|
||||
required=True,
|
||||
select="1"),
|
||||
'default': fields.boolean(
|
||||
'Default Printer',
|
||||
readonly=True),
|
||||
'status': fields.selection(
|
||||
[('unavailable', 'Unavailable'),
|
||||
('printing', 'Printing'),
|
||||
('unknown', 'Unknown'),
|
||||
('available', 'Available'),
|
||||
('error', 'Error'),
|
||||
('server-error', 'Server Error')],
|
||||
'Status', required=True, readonly=True),
|
||||
'status_message': fields.char(
|
||||
'Status Message',
|
||||
size=500,
|
||||
readonly=True),
|
||||
'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"
|
||||
@@ -78,9 +105,9 @@ class printing_printer(orm.Model):
|
||||
server_error = True
|
||||
|
||||
mapping = {
|
||||
3 : 'available',
|
||||
4 : 'printing',
|
||||
5 : 'error'
|
||||
3: 'available',
|
||||
4: 'printing',
|
||||
5: 'error'
|
||||
}
|
||||
|
||||
if context is None:
|
||||
@@ -96,7 +123,7 @@ class printing_printer(orm.Model):
|
||||
status = 'server-error'
|
||||
elif printer.system_name in printers:
|
||||
info = printers[printer.system_name]
|
||||
status = mapping.get( info['printer-state'], 'unknown' )
|
||||
status = mapping.get(info['printer-state'], 'unknown')
|
||||
vals = {
|
||||
'model': info.get('printer-make-and-model', False),
|
||||
'location': info.get('printer-location', False),
|
||||
@@ -117,7 +144,6 @@ class printing_printer(orm.Model):
|
||||
self.updating = False
|
||||
self.last_update = time.time()
|
||||
|
||||
|
||||
def start_printer_update(self, cr, uid, context):
|
||||
self.lock.acquire()
|
||||
if self.updating:
|
||||
@@ -140,7 +166,7 @@ class printing_printer(orm.Model):
|
||||
if not last_update or now - last_update > 10:
|
||||
self.start_printer_update(cr, uid, context)
|
||||
# Wait up to five seconds for printer status update
|
||||
for x in range(0,5):
|
||||
for x in range(0, 5):
|
||||
time.sleep(1)
|
||||
self.lock.acquire()
|
||||
updating = self.updating
|
||||
@@ -149,28 +175,32 @@ class printing_printer(orm.Model):
|
||||
break
|
||||
return True
|
||||
|
||||
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
|
||||
def search(self, cr, uid, args, offset=0, limit=None, order=None,
|
||||
context=None, count=False):
|
||||
self.update(cr, uid, context)
|
||||
return super(printing_printer,self).search(cr, uid, args, offset, limit, order, context, count)
|
||||
return super(printing_printer, self
|
||||
).search(cr, uid, args, offset,
|
||||
limit, order, context, count)
|
||||
|
||||
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
|
||||
self.update(cr, uid, context)
|
||||
return super(printing_printer,self).read(cr, uid, ids, fields, context, load)
|
||||
return super(printing_printer, self
|
||||
).read(cr, uid, ids, fields, context, load)
|
||||
|
||||
def browse(self, cr, uid, ids, context=None):
|
||||
self.update(cr, uid, context)
|
||||
return super(printing_printer,self).browse(cr, uid, ids, context)
|
||||
return super(printing_printer, self).browse(cr, uid, ids, context)
|
||||
|
||||
def set_default(self, cr, uid, ids, context):
|
||||
if not ids:
|
||||
return
|
||||
default_ids= self.search(cr, uid,[('default','=',True)])
|
||||
self.write(cr, uid, default_ids, {'default':False}, context)
|
||||
self.write(cr, uid, ids[0], {'default':True}, context)
|
||||
default_ids = self.search(cr, uid, [('default', '=', True)])
|
||||
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)])
|
||||
def get_default(self, cr, uid, context):
|
||||
printer_ids = self.search(cr, uid, [('default', '=', True)])
|
||||
if printer_ids:
|
||||
return printer_ids[0]
|
||||
return False
|
||||
@@ -182,11 +212,12 @@ class printing_printer(orm.Model):
|
||||
|
||||
def _available_action_types(self, cr, uid, context=None):
|
||||
return [
|
||||
('server',_('Send to Printer')),
|
||||
('client',_('Send to Client')),
|
||||
('user_default',_("Use user's defaults")),
|
||||
('server', _('Send to Printer')),
|
||||
('client', _('Send to Client')),
|
||||
('user_default', _("Use user's defaults")),
|
||||
]
|
||||
|
||||
|
||||
class printing_action(orm.Model):
|
||||
_name = 'printing.action'
|
||||
_description = 'Print Job Action'
|
||||
@@ -195,5 +226,3 @@ class printing_action(orm.Model):
|
||||
'name': fields.char('Name', size=256, required=True),
|
||||
'type': fields.selection(_available_action_types, 'Type', required=True),
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user