Skip to content

Commit d1129d3

Browse files
committed
Merge pull request OCA#2 from yvaucher/7.0-fix-flakes8
7.0 fix flakes8 and makes test green
2 parents 5ee3dc7 + 35e3848 commit d1129d3

File tree

14 files changed

+156
-118
lines changed

14 files changed

+156
-118
lines changed

base_report_to_printer/__openerp__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
'author': 'Agile Business Group & Domsense, Pegueroles SCP, NaN',
8282
'website': 'http://www.agilebg.com',
8383
'license': 'AGPL-3',
84-
"depends" : ['base', 'base_calendar'],
84+
"depends": ['base', 'base_calendar'],
8585
'data': [
8686
'security/security.xml',
8787
'printing_data.xml',

base_report_to_printer/ir_report.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@
3030

3131
from openerp.osv import orm, fields
3232

33-
#
34-
# Reports
35-
#
3633

3734
class report_xml(orm.Model):
38-
35+
"""
36+
Reports
37+
"""
3938

4039
def set_print_options(self, cr, uid, report_id, format, context=None):
4140
"""
@@ -79,7 +78,10 @@ def print_direct(self, cr, uid, report_id, result, format, printer, context=None
7978
method=True,
8079
),
8180
'printing_printer_id': fields.many2one('printing.printer', 'Printer'),
82-
'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'),
81+
'printing_action_ids': fields.one2many(
82+
'printing.report.xml.action', 'report_id', 'Actions',
83+
help='This field allows configuring action and printer on a per '
84+
'user basis'),
8385
}
8486

8587
def behaviour(self, cr, uid, ids, context=None):
@@ -105,16 +107,18 @@ def behaviour(self, cr, uid, ids, context=None):
105107
printer = default_printer
106108

107109
# Retrieve report default values
108-
if report.property_printing_action and report.property_printing_action.type != 'user_default':
110+
if (report.property_printing_action
111+
and report.property_printing_action.type != 'user_default'):
109112
action = report.property_printing_action.type
110113
if report.printing_printer_id:
111114
printer = report.printing_printer_id
112115

113116
# Retrieve report-user specific values
114-
act_ids = printing_act_obj.search(cr, uid,
115-
[('report_id', '=', report.id),
116-
('user_id', '=', uid),
117-
('action', '!=', 'user_default')], context=context)
117+
act_ids = printing_act_obj.search(
118+
cr, uid,
119+
[('report_id', '=', report.id),
120+
('user_id', '=', uid),
121+
('action', '!=', 'user_default')], context=context)
118122
if act_ids:
119123
user_action = printing_act_obj.behaviour(cr, uid, act_ids[0], context)
120124
action = user_action['action']

base_report_to_printer/printing.py

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#
2424
##############################################################################
2525
import time
26-
import base64
2726

2827
import cups
2928
from threading import Thread
@@ -32,25 +31,53 @@
3231
from openerp import pooler
3332
from openerp.osv import orm, fields
3433
from openerp.tools.translate import _
35-
from openerp.addons.base_calendar import base_calendar
3634

3735

38-
#
39-
# Printers
40-
#
4136
class printing_printer(orm.Model):
37+
"""
38+
Printers
39+
"""
4240
_name = "printing.printer"
4341
_description = "Printer"
4442

4543
_columns = {
46-
'name' : fields.char('Name',size=64,required=True,select="1"),
47-
'system_name': fields.char('System Name',size=64,required=True,select="1"),
48-
'default':fields.boolean('Default Printer', readonly=True),
49-
'status': fields.selection([('unavailable','Unavailable'),('printing','Printing'),('unknown','Unknown'),('available','Available'),('error','Error'),('server-error','Server Error')], 'Status', required=True, readonly=True),
50-
'status_message': fields.char('Status Message', size=500, readonly=True),
51-
'model': fields.char('Model', size=500, readonly=True),
52-
'location': fields.char('Location', size=500, readonly=True),
53-
'uri': fields.char('URI', size=500, readonly=True),
44+
'name': fields.char(
45+
'Name',
46+
size=64,
47+
required=True,
48+
select="1"),
49+
'system_name': fields.char(
50+
'System Name',
51+
size=64,
52+
required=True,
53+
select="1"),
54+
'default': fields.boolean(
55+
'Default Printer',
56+
readonly=True),
57+
'status': fields.selection(
58+
[('unavailable', 'Unavailable'),
59+
('printing', 'Printing'),
60+
('unknown', 'Unknown'),
61+
('available', 'Available'),
62+
('error', 'Error'),
63+
('server-error', 'Server Error')],
64+
'Status', required=True, readonly=True),
65+
'status_message': fields.char(
66+
'Status Message',
67+
size=500,
68+
readonly=True),
69+
'model': fields.char(
70+
'Model',
71+
size=500,
72+
readonly=True),
73+
'location': fields.char(
74+
'Location',
75+
size=500,
76+
readonly=True),
77+
'uri': fields.char(
78+
'URI',
79+
size=500,
80+
readonly=True),
5481
}
5582

5683
_order = "name"
@@ -78,9 +105,9 @@ def update_printers_status(self, db_name, uid, context=None):
78105
server_error = True
79106

80107
mapping = {
81-
3 : 'available',
82-
4 : 'printing',
83-
5 : 'error'
108+
3: 'available',
109+
4: 'printing',
110+
5: 'error'
84111
}
85112

86113
if context is None:
@@ -96,7 +123,7 @@ def update_printers_status(self, db_name, uid, context=None):
96123
status = 'server-error'
97124
elif printer.system_name in printers:
98125
info = printers[printer.system_name]
99-
status = mapping.get( info['printer-state'], 'unknown' )
126+
status = mapping.get(info['printer-state'], 'unknown')
100127
vals = {
101128
'model': info.get('printer-make-and-model', False),
102129
'location': info.get('printer-location', False),
@@ -117,7 +144,6 @@ def update_printers_status(self, db_name, uid, context=None):
117144
self.updating = False
118145
self.last_update = time.time()
119146

120-
121147
def start_printer_update(self, cr, uid, context):
122148
self.lock.acquire()
123149
if self.updating:
@@ -140,7 +166,7 @@ def update(self, cr, uid, context=None):
140166
if not last_update or now - last_update > 10:
141167
self.start_printer_update(cr, uid, context)
142168
# Wait up to five seconds for printer status update
143-
for x in range(0,5):
169+
for x in range(0, 5):
144170
time.sleep(1)
145171
self.lock.acquire()
146172
updating = self.updating
@@ -149,28 +175,32 @@ def update(self, cr, uid, context=None):
149175
break
150176
return True
151177

152-
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
178+
def search(self, cr, uid, args, offset=0, limit=None, order=None,
179+
context=None, count=False):
153180
self.update(cr, uid, context)
154-
return super(printing_printer,self).search(cr, uid, args, offset, limit, order, context, count)
181+
return super(printing_printer, self
182+
).search(cr, uid, args, offset,
183+
limit, order, context, count)
155184

156185
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
157186
self.update(cr, uid, context)
158-
return super(printing_printer,self).read(cr, uid, ids, fields, context, load)
187+
return super(printing_printer, self
188+
).read(cr, uid, ids, fields, context, load)
159189

160190
def browse(self, cr, uid, ids, context=None):
161191
self.update(cr, uid, context)
162-
return super(printing_printer,self).browse(cr, uid, ids, context)
192+
return super(printing_printer, self).browse(cr, uid, ids, context)
163193

164194
def set_default(self, cr, uid, ids, context):
165195
if not ids:
166196
return
167-
default_ids= self.search(cr, uid,[('default','=',True)])
168-
self.write(cr, uid, default_ids, {'default':False}, context)
169-
self.write(cr, uid, ids[0], {'default':True}, context)
197+
default_ids = self.search(cr, uid, [('default', '=', True)])
198+
self.write(cr, uid, default_ids, {'default': False}, context)
199+
self.write(cr, uid, ids[0], {'default': True}, context)
170200
return True
171201

172-
def get_default(self,cr,uid,context):
173-
printer_ids = self.search(cr, uid,[('default','=',True)])
202+
def get_default(self, cr, uid, context):
203+
printer_ids = self.search(cr, uid, [('default', '=', True)])
174204
if printer_ids:
175205
return printer_ids[0]
176206
return False
@@ -182,11 +212,12 @@ def get_default(self,cr,uid,context):
182212

183213
def _available_action_types(self, cr, uid, context=None):
184214
return [
185-
('server',_('Send to Printer')),
186-
('client',_('Send to Client')),
187-
('user_default',_("Use user's defaults")),
215+
('server', _('Send to Printer')),
216+
('client', _('Send to Client')),
217+
('user_default', _("Use user's defaults")),
188218
]
189219

220+
190221
class printing_action(orm.Model):
191222
_name = 'printing.action'
192223
_description = 'Print Job Action'
@@ -195,5 +226,3 @@ class printing_action(orm.Model):
195226
'name': fields.char('Name', size=256, required=True),
196227
'type': fields.selection(_available_action_types, 'Type', required=True),
197228
}
198-
199-
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

base_report_to_printer/report_service.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from openerp import pooler
2828
from openerp.addons.base_calendar import base_calendar
2929

30+
3031
class virtual_report_spool(base_calendar.virtual_report_spool):
3132

3233
def exp_report(self, db, uid, object, ids, datas=None, context=None):
@@ -41,22 +42,26 @@ def exp_report_get(self, db, uid, report_id):
4142
pool = pooler.get_pool(cr.dbname)
4243
# First of all load report defaults: name, action and printer
4344
report_obj = pool.get('ir.actions.report.xml')
44-
report = report_obj.search(cr,uid,[('report_name','=',self._reports[report_id]['report_name'])])
45+
report = report_obj.search(
46+
cr, uid, [('report_name', '=', self._reports[report_id]['report_name'])])
4547
if report:
46-
report = report_obj.browse(cr,uid,report[0])
47-
name = report.name
48+
report = report_obj.browse(cr, uid, report[0])
4849
data = report.behaviour()[report.id]
4950
action = data['action']
5051
printer = data['printer']
5152
if action != 'client':
52-
if (self._reports and self._reports.get(report_id, False) and self._reports[report_id].get('result', False)
53-
and self._reports[report_id].get('format', False)):
54-
report_obj.print_direct(cr, uid, report.id, base64.encodestring(self._reports[report_id]['result']),
53+
if (self._reports and self._reports.get(report_id, False)
54+
and self._reports[report_id].get('result', False)
55+
and self._reports[report_id].get('format', False)):
56+
report_obj.print_direct(
57+
cr, uid, report.id, base64.encodestring(self._reports[report_id]['result']),
5558
self._reports[report_id]['format'], printer)
56-
# XXX "Warning" removed as it breaks the workflow
59+
# FIXME "Warning" removed as it breaks the workflow
5760
# it would be interesting to have a dialog box to confirm if we really want to print
5861
# in this case it must be with a by pass parameter to allow massive impression
59-
#raise osv.except_osv(_('Printing...'), _('Document sent to printer %s') % (printer,))
62+
# raise osv.except_osv(
63+
# _('Printing...'),
64+
# _('Document sent to printer %s') % (printer,))
6065

6166
except:
6267
cr.rollback()

base_report_to_printer/users.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@
2626

2727
from printing import _available_action_types
2828

29-
#
30-
# Users
31-
#
29+
3230
class res_users(orm.Model):
31+
"""
32+
Users
33+
"""
3334
_name = "res.users"
3435
_inherit = "res.users"
3536

3637
def _user_available_action_types(self, cr, uid, context=None):
3738
if context is None:
38-
context={}
39-
return [x for x in _available_action_types(self, cr, uid, context) if x[0] != 'user_default']
39+
context = {}
40+
return [x for x in _available_action_types(self, cr, uid, context)
41+
if x[0] != 'user_default']
4042

4143
_columns = {
4244
'printing_action': fields.selection(_user_available_action_types, 'Printing Action'),

base_report_to_printer/wizard/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
##############################################################################
3-
#
3+
#
44
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
55
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
66
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)

base_report_to_printer/wizard/update_printers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
##############################################################################
3-
#
3+
#
44
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
55
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
66
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
@@ -37,14 +37,16 @@ def action_cancel(self, cr, uid, ids, context=None):
3737

3838
def action_ok(self, cr, uid, ids, context=None):
3939
# Update Printers
40+
printer_obj = self.pool['printing.printer']
4041
try:
4142
connection = cups.Connection()
4243
printers = connection.getPrinters()
4344
except:
4445
return {}
4546

46-
ids = self.pool.get('printing.printer').search(cr, uid, [('system_name','in',printers.keys())], context=context)
47-
for printer in self.pool.get('printing.printer').browse(cr, uid, ids, context=context):
47+
ids = printer_obj.search(
48+
cr, uid, [('system_name', 'in', printers.keys())], context=context)
49+
for printer in printer_obj.browse(cr, uid, ids, context=context):
4850
del printers[printer.system_name]
4951

5052
for name in printers:

pingen/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@
2323
import pingen
2424
import pingen_document
2525
import res_company
26-

0 commit comments

Comments
 (0)