[IMP] Renamed photo_stored->photo_big, which makes more sens. Updated demo data.

bzr revid: tde@openerp.com-20120323121438-upcgpsvy809hm2n5
This commit is contained in:
Thibault Delavallée 2012-03-23 13:14:38 +01:00
parent 3211541cf7
commit 0bcf800119
3 changed files with 20 additions and 20 deletions

View File

@ -2,7 +2,8 @@ HR photo specs
==============
This revision modifies the photo for HR employees. Two fields now exist in the hr.employee model:
- 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.
- photo_big, a binary field holding the image. It is base-64 encoded, and PIL-supported. It is automatically resized as an 540x450 px image.
- 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 the photo through the photo function field, the new image is automatically resized to 540x450, and stored in the photo_big field. This triggers the function field, that will compute a 180x150 resized version of the image.
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.

View File

@ -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, 540, 450, context=context), 'photo': self._photo_resize(cr, uid, value, context=context) } }
return {'value': {'photo_big': 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': self._photo_resize(cr, uid, value, 540, 450, context=context)}, context=context)
return self.write(cr, uid, [id], {'photo_big': 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'))
@ -166,8 +166,8 @@ class hr_employee(osv.osv):
def _get_photo(self, cr, uid, ids, name, args, context=None):
result = dict.fromkeys(ids, False)
for hr_empl in self.browse(cr, uid, ids, context=context):
if hr_empl.photo_stored:
result[hr_empl.id] = self._photo_resize(cr, uid, hr_empl.photo_stored, context=context)
if hr_empl.photo_big:
result[hr_empl.id] = self._photo_resize(cr, uid, hr_empl.photo_big, context=context)
return result
_columns = {
@ -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 are resized to 540x450 px."),
'photo_big': fields.binary('Big-sized employee 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. Full-sized photo are however 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. A larger photo is stored inside the photo_stored field."),
'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['photo_big'], 10),
}, 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_big 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,7 +250,6 @@ class hr_employee(osv.osv):
_defaults = {
'active': 1,
'photo_stored': _get_photo,
'photo': _get_photo,
'marital': 'single',
'color': 0,

File diff suppressed because one or more lines are too long