[IMP] hr: image is not modified at display when choosing a new one; btu resized when...
[odoo/odoo.git] / addons / hr / hr.py
index cc3c4fa..a153d63 100644 (file)
@@ -106,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,34 +147,21 @@ class hr_employee(osv.osv):
     _description = "Employee"
     _inherits = {'resource.resource': "resource_id"}
 
-    def _get_image_resized(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_employee in self.browse(cr, uid, ids, context=context):
-            result[hr_employee.id] = {'image_medium': False, 'image_small': False}
-            if hr_employee.image:
-                result[hr_employee.id]['image_medium'] = tools.resize_image_medium(hr_employee.image)
-                result[hr_employee.id]['image_small'] = tools.resize_image_small(hr_employee.image)
+        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_resized(self, cr, uid, id, name, value, args, context=None):
-        if not value:
-            vals = {'image': value}
-        else:
-            vals = {'image': tools.resize_image_big(value)}
-        return self.write(cr, uid, [id], vals, context=context)
+    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):
-        if not value:
-            return {'value': {
-                    'image': value,
-                    'image_medium': value,
-                    'image_small': value,
-                    }}
-        return {'value': {
-                    'image': tools.resize_image_big(value),
-                    'image_medium': tools.resize_image_medium(value),
-                    'image_small': tools.resize_image_small(value),
-                    }}
+        return {'value': {'image_medium': tools.resize_image_big(value), 'image_small': tools.resize_image_big(value)}}
     
     _columns = {
         'country_id': fields.many2one('res.country', 'Nationality'),
@@ -201,27 +188,25 @@ class hr_employee(osv.osv):
         'coach_id': fields.many2one('hr.employee', 'Coach'),
         'job_id': fields.many2one('hr.job', 'Job'),
         'image': fields.binary("Photo",
-            help="This field holds the photo used as image for the "\
-                 "user. The avatar field is used as an interface to "\
-                 "access this field. The image is base64 encoded, "\
-                 "and PIL-supported. It is stored as a 540x450 px "\
-                 "image, in case a bigger image must be used."),
-        'image_medium': fields.function(_get_image_resized, fnct_inv=_set_image_resized,
-            string="Medium-sized photo", type="binary", multi="_get_image_resized",
+            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 1024x1024 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 user. It is automatically "\
-                 "resized as a 180x180px image, with aspect ratio keps. "\
+            help="Medium-sized photo of the employee. It is automatically "\
+                 "resized as a 180x180 px image, with aspect ratio preserved. "\
                  "Use this field in form views or some kanban views."),
-        'image_small': fields.function(_get_image_resized, fnct_inv=_set_image_resized,
-            string="Smal-sized photo", type="binary", multi="_get_image_resized",
+        '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, ['image'], 10),
             },
-            help="Small-sized photo of the user. It is automatically "\
-                 "resized as a 50x50px image, with aspect ratio keps. "\
-                 "Use this field in form views or some kanban views."),
+            help="Small-sized photo of the employee. It is automatically "\
+                 "resized as a 50x50 px image, with aspect ratio preserved. "\
+                 "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'),
@@ -230,6 +215,16 @@ class hr_employee(osv.osv):
         'last_login': fields.related('user_id', 'date', type='datetime', string='Latest Connection', readonly=1),
     }
 
+    def create(self, cr, uid, data, context=None):
+        employee_id = super(hr_employee, self).create(cr, uid, data, context=context)
+        try:
+            (model, mail_group_id) = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'group_all_employees')
+            employee = self.browse(cr, uid, employee_id, context=context)
+            self.pool.get('mail.group').message_append_note(cr, uid, [mail_group_id], body='Welcome to %s! Please help him make its first steps in OpenERP!' % (employee.name), context=context)
+        except:
+            pass # group deleted: do not push a message
+        return employee_id
+
     def unlink(self, cr, uid, ids, context=None):
         resource_obj = self.pool.get('resource.resource')
         resource_ids = []
@@ -268,13 +263,13 @@ class hr_employee(osv.osv):
             work_email = self.pool.get('res.users').browse(cr, uid, user_id, context=context).user_email
         return {'value': {'work_email' : work_email}}
 
-    def _get_photo(self, cr, uid, context=None):
-        image_path = addons.get_module_resource('hr', 'images', 'photo.png')
+    def _get_default_image(self, cr, uid, context=None):
+        image_path = addons.get_module_resource('hr', 'static/src/img', 'default_image.png')
         return tools.resize_image_big(open(image_path, 'rb').read().encode('base64'))
 
     _defaults = {
         'active': 1,
-        'image_medium': _get_photo,
+        'image': _get_default_image,
         'marital': 'single',
         'color': 0,
     }
@@ -327,6 +322,10 @@ class res_users(osv.osv):
 
         return user_id
 
+    _columns = {
+        'employee_ids': fields.one2many('hr.employee', 'user_id', 'Related employees'),
+        }
+
 res_users()