mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
Migrate wizard/update_printers.py to new API
This commit is contained in:
committed by
Sylvain GARANCHER
parent
fe3ab51f5a
commit
05982df305
@@ -4,7 +4,7 @@
|
|||||||
# 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>)
|
||||||
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
|
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
|
||||||
# All Rights Reserved
|
# Copyright (C) 2014 Camptocamp SA (<http://www.camptocamp.com>)
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as published
|
# it under the terms of the GNU Affero General Public License as published
|
||||||
@@ -23,41 +23,38 @@
|
|||||||
|
|
||||||
import cups
|
import cups
|
||||||
|
|
||||||
from openerp.osv import orm
|
from openerp import models, api
|
||||||
|
|
||||||
|
|
||||||
class printing_printer_update_wizard(orm.TransientModel):
|
class PrintingPrinterUpdateWizard(models.TransientModel):
|
||||||
_name = "printing.printer.update.wizard"
|
_name = 'printing.printer.update.wizard'
|
||||||
|
|
||||||
_columns = {
|
@api.multi
|
||||||
}
|
def action_ok(self):
|
||||||
|
self.ensure_one()
|
||||||
def action_cancel(self, cr, uid, ids, context=None):
|
|
||||||
return {}
|
|
||||||
|
|
||||||
def action_ok(self, cr, uid, ids, context=None):
|
|
||||||
# Update Printers
|
# Update Printers
|
||||||
printer_obj = self.pool['printing.printer']
|
printer_obj = self.env['printing.printer']
|
||||||
try:
|
try:
|
||||||
connection = cups.Connection()
|
connection = cups.Connection()
|
||||||
printers = connection.getPrinters()
|
printers = connection.getPrinters()
|
||||||
except:
|
except:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
ids = printer_obj.search(
|
printer_recs = printer_obj.search(
|
||||||
cr, uid, [('system_name', 'in', printers.keys())], context=context)
|
[('system_name', 'in', printers.keys())]
|
||||||
for printer in printer_obj.browse(cr, uid, ids, context=context):
|
)
|
||||||
|
for printer in printer_recs:
|
||||||
del printers[printer.system_name]
|
del printers[printer.system_name]
|
||||||
|
|
||||||
for name in printers:
|
for name, printer in printers.iteritems():
|
||||||
printer = printers[name]
|
values = {
|
||||||
self.pool.get('printing.printer').create(cr, uid, {
|
|
||||||
'name': printer['printer-info'],
|
'name': printer['printer-info'],
|
||||||
'system_name': name,
|
'system_name': name,
|
||||||
'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)
|
}
|
||||||
|
self.env['printing.printer'].create(values)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'name': 'Printers',
|
'name': 'Printers',
|
||||||
@@ -67,6 +64,3 @@ class printing_printer_update_wizard(orm.TransientModel):
|
|||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
'target': 'current',
|
'target': 'current',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
||||||
|
|||||||
Reference in New Issue
Block a user