1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2008-2013 Alistek Ltd (http://www.alistek.com) All Rights Reserved.
5
# General contacts <info@alistek.com>
7
# WARNING: This program as such is intended to be used by professional
8
# programmers who take the whole responsability of assessing all potential
9
# consequences resulting from its eventual inadequacies and bugs
10
# End users who are looking for a ready-to-use solution with commercial
11
# garantees and support are strongly adviced to contract a Free Software
14
# This program is Free Software; you can redistribute it and/or
15
# modify it under the terms of the GNU General Public License
16
# as published by the Free Software Foundation; either version 3
17
# of the License, or (at your option) any later version.
19
# This module is GPLv3 or newer and incompatible
20
# with OpenERP SA "AGPL + Private Use License"!
22
# This program is distributed in the hope that it will be useful,
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
# GNU General Public License for more details.
27
# You should have received a copy of the GNU General Public License
28
# along with this program; if not, write to the Free Software
29
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31
##############################################################################
33
from osv import fields
40
_url = 'http://www.alistek.com/aeroo_banner/v6_0_report_aeroo_direct_print.png'
42
class aeroo_printer_installer(osv.osv_memory):
43
_name = 'aeroo_printer.installer'
44
_inherit = 'res.config.installer'
47
def _get_image(self, cr, uid, context=None):
49
return self._logo_image
51
im = urllib2.urlopen(_url.encode("UTF-8"))
52
if im.headers.maintype!='image':
53
raise TypeError(im.headers.maintype)
55
path = os.path.join('report_aeroo','config_pixmaps','module_banner.png')
56
image_file = file_data = tools.file_open(path,'rb')
58
file_data = image_file.read()
59
self._logo_image = base64.encodestring(file_data)
60
return self._logo_image
64
self._logo_image = base64.encodestring(im.read())
65
return self._logo_image
67
def _get_image_fn(self, cr, uid, ids, name, args, context=None):
68
image = self._get_image(cr, uid, context)
69
return dict.fromkeys(ids, image) # ok to use .fromkeys() as the image is same for all
72
'printer_ids':fields.one2many('aeroo.printers.temp', 'install_id', 'Printers'),
73
'config_logo': fields.function(_get_image_fn, string='Image', type='binary', method=True),
74
'state':fields.selection([
78
],'State', select=True, readonly=True),
81
def default_get(self, cr, uid, fields, context=None):
82
printers_obj = self.pool.get('aeroo.printers')
83
data = super(aeroo_printer_installer, self).default_get(cr, uid, fields, context=context)
84
conn = cups.Connection()
85
printers = conn.getPrinters()
86
installed_ids = printers_obj.search(cr, 1, ['|',('active','=',False),('active','=',True)], context=context)
87
printers_installed = printers_obj.read(cr, uid, installed_ids, context=context)
88
new_printers = list(set(printers.keys()).difference(set(map(lambda p: p['code'], printers_installed))))
90
data['printer_ids'] = []
91
for p in printers_installed:
94
del p_temp['group_ids']
96
p_temp['state'] = 'connected'
97
data['printer_ids'].append(p_temp)
99
for new_p in new_printers:
100
note = '\n'.join(map(lambda key: "%s: %s" % (key, printers[new_p][key]), printers[new_p]))
101
p_temp = {'name':printers[new_p]['printer-info'],'code':new_p,'state':'new','note':note}
102
data['printer_ids'].append(p_temp)
107
def process(self, cr, uid, ids, context=None):
108
printers_obj = self.pool.get('aeroo.printers')
109
this = self.browse(cr, uid, ids[0], context=context)
111
for printer in this.printer_ids:
112
if printer.state=='new' and not printers_obj.search(cr, uid, [('code','=',printer.code)], context=context):
113
printers_obj.create(cr, uid, {'name':printer.name,
117
conn_printers.append((1, printer.id, {'state':'connected'}))
119
return this.write({'state':'done','printer_ids':conn_printers})
123
'config_logo': _get_image,
126
aeroo_printer_installer()
128
class aeroo_printers_temp(osv.osv_memory):
129
_name = 'aeroo.printers.temp'
132
'name':fields.char('Description', size=256, required=True),
133
'code':fields.char('Name', size=64, required=True),
134
'note': fields.text('Details'),
135
'install_id':fields.many2one('aeroo_printer.installer', 'Install Id'),
136
'state':fields.selection([
137
('connected','Connected'),
140
],'State', select=True, readonly=True),
143
aeroo_printers_temp()