[IMP] Improved comments and doc. Note that stored photo is now resized to 540x450 maximum.
bzr revid: tde@openerp.com-20120323103308-br79vii176ncj5z0
This commit is contained in:
@@ -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.
|
||||
|
||||
+5
-4
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user