From 3211541cf7c2c0f0554e13b6c487fd32210294b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Mar 2012 11:33:08 +0100 Subject: [PATCH] [IMP] Improved comments and doc. Note that stored photo is now resized to 540x450 maximum. bzr revid: tde@openerp.com-20120323103308-br79vii176ncj5z0 --- addons/hr/doc/hr_employee_img.rst | 6 +++--- addons/hr/hr.py | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/addons/hr/doc/hr_employee_img.rst b/addons/hr/doc/hr_employee_img.rst index 0c7ca0bd9c6..43bbda784ad 100644 --- a/addons/hr/doc/hr_employee_img.rst +++ b/addons/hr/doc/hr_employee_img.rst @@ -2,7 +2,7 @@ HR photo specs ============== This revision modifies the photo for HR employees. Two fields now exist in the hr.employee model: - - photo, a binary field holding the image - - photo_mini, a binary field holding an automatically resized version of the avatar. Dimensions of the resized avatar are 180x150. + - photo_stored, a binary field holding the image. It is base-64 encoded, and PIL-supported. + - photo, a functional binary field holding an automatically resized version of the photo. Dimensions of the resized photo are 180x150. This field is used as an inteface to get and set the employee photo. When changing this field in a view, the new image is automatically resized, and stored in the photo_stored field. Note that the value is stored on another field, because otherwise it would imply to write on the function field, which currently using OpenERP 6.1 can lead to issues. -Employee photo should be used only when dealing with employees, using the photo_mini field. When dealing with users, use the res.users avatar_mini field instead. +Employee photo should be used only when dealing with employees, using the photo field. When dealing with users, use the res.users avatar field instead. diff --git a/addons/hr/hr.py b/addons/hr/hr.py index 969e052e0d0..d46f0e6e1ad 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -150,10 +150,10 @@ class hr_employee(osv.osv): _inherits = {'resource.resource': "resource_id"} def onchange_photo(self, cr, uid, ids, value, context=None): - return {'value': {'photo_stored': self._photo_resize(cr, uid, value, 360, 300, context=context), 'photo': self._photo_resize(cr, uid, value, context=context) } } + return {'value': {'photo_stored': self._photo_resize(cr, uid, value, 540, 450, context=context), 'photo': self._photo_resize(cr, uid, value, context=context) } } def _set_photo(self, cr, uid, id, name, value, args, context=None): - return self.write(cr, uid, [id], {'photo_stored': value}, context=context) + return self.write(cr, uid, [id], {'photo_stored': self._photo_resize(cr, uid, value, 540, 450, context=context)}, context=context) def _photo_resize(self, cr, uid, photo, heigth=180, width=150, context=None): image_stream = io.BytesIO(photo.decode('base64')) @@ -195,11 +195,11 @@ class hr_employee(osv.osv): 'resource_id': fields.many2one('resource.resource', 'Resource', ondelete='cascade', required=True), 'coach_id': fields.many2one('hr.employee', 'Coach'), 'job_id': fields.many2one('hr.job', 'Job'), - 'photo_stored': fields.binary('Stored photo', help="This field holds the photo of the employee. The photo field is used as an interface to access this field. The image is base64 encoded, and PIL-supported. Stored photo through the interface are resized to 360x300 px."), + 'photo_stored': fields.binary('Stored photo', help="This field holds the photo of the employee. The photo field is used as an interface to access this field. The image is base64 encoded, and PIL-supported. Stored photo are resized to 540x450 px."), 'photo': fields.function(_get_photo, fnct_inv=_set_photo, string='Employee photo', type="binary", store = { 'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['photo_stored'], 10), - }, help="Image used as photo for the employee. It is automatically resized as a 180x150 px image."), + }, help="Image used as photo for the employee. It is automatically resized as a 180x150 px image. A larger photo is stored inside the photo_stored field."), 'passport_id':fields.char('Passport No', size=64), 'color': fields.integer('Color Index'), 'city': fields.related('address_id', 'city', type='char', string='City'), @@ -250,6 +250,7 @@ class hr_employee(osv.osv): _defaults = { 'active': 1, + 'photo_stored': _get_photo, 'photo': _get_photo, 'marital': 'single', 'color': 0,