[MERGE] Merged with branch adding a miniature to employee. Not a real feature of OpenSocial, but comes with gravatar replacement feature.

bzr revid: tde@openerp.com-20120221154522-e02pd35s8u7p4d1x
This commit is contained in:
Thibault Delavallée
2012-02-21 16:45:22 +01:00
2 changed files with 29 additions and 1 deletions
+28
View File
@@ -23,6 +23,9 @@ from osv import fields, osv
import logging
import addons
import io, StringIO
from PIL import Image
class hr_employee_category(osv.osv):
def name_get(self, cr, uid, ids, context=None):
@@ -145,6 +148,27 @@ class hr_employee(osv.osv):
_name = "hr.employee"
_description = "Employee"
_inherits = {'resource.resource': "resource_id"}
def _get_photo_mini(self, cr, uid, ids, name, args, context=None):
result = {}
for obj in self.browse(cr, uid, ids, context=context):
print obj
if not obj.photo:
result[obj.id] = False
continue
image_stream = io.BytesIO(obj.photo.decode('base64'))
img = Image.open(image_stream)
img.thumbnail((180, 150), Image.ANTIALIAS)
img_stream = StringIO.StringIO()
img.save(img_stream, "JPEG")
result[obj.id] = img_stream.getvalue().encode('base64')
return result
def _set_photo_mini(self, cr, uid, id, name, value, args, context=None):
self.write(cr, uid, [id], {'photo': value}, context=context)
return True
_columns = {
'country_id': fields.many2one('res.country', 'Nationality'),
'birthday': fields.date("Date of Birth"),
@@ -171,6 +195,10 @@ class hr_employee(osv.osv):
'coach_id': fields.many2one('hr.employee', 'Coach'),
'job_id': fields.many2one('hr.job', 'Job'),
'photo': fields.binary('Photo'),
'photo_mini': fields.function(_get_photo_mini, fnct_inv=_set_photo_mini, string='Photo Mini', type="binary",
store = {
'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10),
}),
'passport_id':fields.char('Passport No', size=64),
'color': fields.integer('Color Index'),
'city': fields.related('address_id', 'city', type='char', string='City'),
+1 -1
View File
@@ -33,7 +33,7 @@
<field name="parent_id" />
</group>
<group colspan="2" col="1">
<field name="photo" widget='image' nolabel="1"/>
<field name="photo_mini" widget='image' nolabel="1"/>
</group>
</group>
<notebook colspan="6">