mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[PEP8] - printer_tray
This commit is contained in:
@@ -47,7 +47,7 @@ Report to printer - Paper tray selection
|
||||
'data': [
|
||||
'users_view.xml',
|
||||
'ir_report_view.xml',
|
||||
],
|
||||
],
|
||||
'test': [],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
|
||||
@@ -29,14 +29,15 @@ class ReportXML(orm.Model):
|
||||
'printer_tray_id': fields.many2one(
|
||||
'printing.tray', 'Paper Source',
|
||||
domain="[('printer_id', '=', printing_printer_id)]"),
|
||||
}
|
||||
}
|
||||
|
||||
def set_print_options(self, cr, uid, report_id, format, context=None):
|
||||
"""
|
||||
Hook to define Tray
|
||||
"""
|
||||
printing_act_obj = self.pool.get('printing.report.xml.action')
|
||||
options = super(ReportXML, self).set_print_options(cr, uid, report_id, format, context=context)
|
||||
options = super(ReportXML, self).set_print_options(
|
||||
cr, uid, report_id, format, context=context)
|
||||
|
||||
# Retrieve user default values
|
||||
user = self.pool.get('res.users').browse(cr, uid, context)
|
||||
@@ -54,7 +55,8 @@ class ReportXML(orm.Model):
|
||||
('user_id', '=', uid),
|
||||
('action', '!=', 'user_default')], context=context)
|
||||
if act_ids:
|
||||
user_action = printing_act_obj.browse(cr, uid, act_ids[0], context=context)
|
||||
user_action = printing_act_obj.browse(
|
||||
cr, uid, act_ids[0], context=context)
|
||||
if user_action.tray_id:
|
||||
tray = user_action.tray_id
|
||||
|
||||
|
||||
@@ -30,8 +30,9 @@ class Printer(orm.Model):
|
||||
_inherit = 'printing.printer'
|
||||
|
||||
_columns = {
|
||||
'tray_ids': fields.one2many('printing.tray', 'printer_id', 'Paper Sources'),
|
||||
}
|
||||
'tray_ids': fields.one2many('printing.tray', 'printer_id',
|
||||
'Paper Sources'),
|
||||
}
|
||||
|
||||
def _update_tray_option(self, db_name, uid, printer, context=None):
|
||||
"""
|
||||
@@ -54,12 +55,13 @@ class Printer(orm.Model):
|
||||
return
|
||||
try:
|
||||
for tray_opt in option.choices:
|
||||
if tray_opt['choice'] not in [t.system_name for t in printer.tray_ids]:
|
||||
if tray_opt['choice'] not in [
|
||||
t.system_name for t in printer.tray_ids]:
|
||||
tray_vals = {
|
||||
'name': tray_opt['text'],
|
||||
'system_name': tray_opt['choice'],
|
||||
'printer_id': printer.id,
|
||||
}
|
||||
}
|
||||
|
||||
tray_obj.create(cr, uid, tray_vals, context=context)
|
||||
cr.commit()
|
||||
@@ -76,7 +78,8 @@ class Printer(orm.Model):
|
||||
"""
|
||||
db, pool = pooler.get_db_and_pool(db_name)
|
||||
cr = db.cursor()
|
||||
res = super(Printer, self).update_printers_status(db_name, uid, context=context)
|
||||
res = super(Printer, self).update_printers_status(db_name, uid,
|
||||
context=context)
|
||||
try:
|
||||
connection = cups.Connection()
|
||||
printers = connection.getPrinters()
|
||||
@@ -84,7 +87,9 @@ class Printer(orm.Model):
|
||||
except:
|
||||
server_error = True
|
||||
|
||||
printer_ids = self.search(cr, uid, [('system_name', 'in', printers.keys())], context=context)
|
||||
printer_ids = self.search(cr, uid,
|
||||
[('system_name', 'in', printers.keys())],
|
||||
context=context)
|
||||
if server_error:
|
||||
vals = {'status': 'server_error'}
|
||||
self.write(cr, uid, printer_ids, vals, context=context)
|
||||
@@ -95,5 +100,6 @@ class Printer(orm.Model):
|
||||
for printer in printer_list:
|
||||
# XXX we consider config of printer won't change
|
||||
if not printer.tray_ids:
|
||||
self._update_tray_option(db_name, uid, printer, context=context)
|
||||
self._update_tray_option(db_name, uid, printer,
|
||||
context=context)
|
||||
return res
|
||||
|
||||
@@ -29,5 +29,6 @@ class PrinterTray(orm.Model):
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=64, required=True),
|
||||
'system_name': fields.char('System Name', size=64, required=True),
|
||||
'printer_id': fields.many2one('printing.printer', 'Printer', required=True),
|
||||
}
|
||||
'printer_id': fields.many2one('printing.printer', 'Printer',
|
||||
required=True),
|
||||
}
|
||||
|
||||
@@ -29,10 +29,11 @@ class ReportXMLAction(orm.Model):
|
||||
'printer_tray_id': fields.many2one(
|
||||
'printing.tray', 'Paper Source',
|
||||
domain="[('printer_id', '=', printer_id)]"),
|
||||
}
|
||||
}
|
||||
|
||||
def behaviour(self, cr, uid, act_id, context=None):
|
||||
res = super(ReportXMLAction, self).behaviour(cr, uid, act_id, context=context)
|
||||
res = super(ReportXMLAction, self).behaviour(cr, uid, act_id,
|
||||
context=context)
|
||||
action = self.browse(cr, uid, act_id, context=context)
|
||||
res['tray'] = action.printer_tray_id.system_name
|
||||
return res
|
||||
|
||||
@@ -29,4 +29,4 @@ class ResUsers(orm.Model):
|
||||
'printer_tray_id': fields.many2one(
|
||||
'printing.tray', 'Default Printer Paper Source',
|
||||
domain="[('printer_id', '=', printing_printer_id)]"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user