From: Thibault Delavallée Date: Thu, 28 Jun 2012 12:44:20 +0000 (+0200) Subject: [MERGE] Merged with main addons. X-Git-Tag: 7.0-server~2613^2~25 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=282f72391b9d3a2de8b68abcdf6c8857c62b00e5;hp=-c;p=odoo%2Fodoo.git [MERGE] Merged with main addons. bzr revid: tde@openerp.com-20120628124420-bxjjo2jhtzps0wsf --- 282f72391b9d3a2de8b68abcdf6c8857c62b00e5 diff --combined addons/hr/hr.py index 594f0b2,44b533f..9864b73 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@@ -20,9 -20,11 +20,9 @@@ ############################################################################## import addons -import io import logging from osv import fields, osv -from PIL import Image -import StringIO +import tools _logger = logging.getLogger(__name__) class hr_employee_category(osv.osv): @@@ -106,7 -108,7 +106,7 @@@ class hr_job(osv.osv) }, multi='no_of_employee'), 'no_of_recruitment': fields.float('Expected in Recruitment', help='Number of new employees you expect to recruit.'), - 'employee_ids': fields.one2many('hr.employee', 'job_id', 'Employees'), + 'employee_ids': fields.one2many('hr.employee', 'job_id', 'Employees', groups='base.group_user'), 'description': fields.text('Job Description'), 'requirements': fields.text('Requirements'), 'department_id': fields.many2one('hr.department', 'Department'), @@@ -147,22 -149,33 +147,22 @@@ class hr_employee(osv.osv) _description = "Employee" _inherits = {'resource.resource': "resource_id"} - def onchange_photo(self, cr, uid, ids, value, context=None): - if not value: - return {'value': {'photo_big': value, 'photo': value} } - 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): - if not value: - vals = {'photo_big': value} - else: - vals = {'photo_big': self._photo_resize(cr, uid, value, 540, 450, context=context)} - return self.write(cr, uid, [id], vals, context=context) - - def _photo_resize(self, cr, uid, photo, heigth=180, width=150, context=None): - image_stream = io.BytesIO(photo.decode('base64')) - img = Image.open(image_stream) - img.thumbnail((heigth, width), Image.ANTIALIAS) - img_stream = StringIO.StringIO() - img.save(img_stream, "JPEG") - return img_stream.getvalue().encode('base64') - - def _get_photo(self, cr, uid, ids, name, args, context=None): + def _get_image(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_big: - result[hr_empl.id] = self._photo_resize(cr, uid, hr_empl.photo_big, context=context) + for obj in self.browse(cr, uid, ids, context=context): + resized_image_dict = tools.get_resized_images(obj.image) + result[obj.id] = { + 'image_medium': resized_image_dict['image_medium'], + 'image_small': resized_image_dict['image_small'], + } return result + def _set_image(self, cr, uid, id, name, value, args, context=None): + return self.write(cr, uid, [id], {'image': tools.resize_image_big(value)}, context=context) + + def onchange_image(self, cr, uid, ids, value, context=None): + return {'value': tools.get_resized_images(value)} + _columns = { 'country_id': fields.many2one('res.country', 'Nationality'), 'birthday': fields.date("Date of Birth"), @@@ -187,27 -200,11 +187,27 @@@ '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_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", + 'image': fields.binary("Photo", + help="This field holds the image used as a photo for the "\ + "employee. The image is base64 encoded, and PIL-supported. "\ + "It is limited to a 12024x1024 px image."), + 'image_medium': fields.function(_get_image, fnct_inv=_set_image, + string="Medium-sized photo", type="binary", multi="_get_image", + store = { + 'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Medium-sized photo of the employee. It is automatically "\ + "resized as a 180x180px image, with aspect ratio kept. "\ + "Use this field in form views or some kanban views."), + 'image_small': fields.function(_get_image, fnct_inv=_set_image, + string="Smal-sized photo", type="binary", multi="_get_image", store = { - '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."), + 'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Small-sized photo of the employee. It is automatically "\ + "resized as a 50x50px image, with aspect ratio keps. "\ + "Use this field anywhere a small image is required."), + 'active': fields.boolean('Active'), 'passport_id':fields.char('Passport No', size=64), 'color': fields.integer('Color Index'), 'city': fields.related('address_id', 'city', type='char', string='City'), @@@ -254,12 -251,12 +254,12 @@@ return {'value': {'work_email' : work_email}} def _get_photo(self, cr, uid, context=None): - photo_path = addons.get_module_resource('hr','images','photo.png') - return self._photo_resize(cr, uid, open(photo_path, 'rb').read().encode('base64'), context=context) + image_path = addons.get_module_resource('hr', 'images', 'photo.png') + return tools.resize_image_big(open(image_path, 'rb').read().encode('base64')) _defaults = { 'active': 1, - 'photo': _get_photo, + 'image': _get_photo, 'marital': 'single', 'color': 0, } diff --combined addons/hr/hr_view.xml index 72a0c8c,4d6a844..e6478dc --- a/addons/hr/hr_view.xml +++ b/addons/hr/hr_view.xml @@@ -10,11 -10,7 +10,7 @@@ - + hr.employee.form hr.employee @@@ -25,7 -21,7 +21,7 @@@
- +