@@ -304,7 +304,10 @@
|
||||
<field name="company_currency"/>
|
||||
</t>
|
||||
</td>
|
||||
<td valign="top" width="22"><img t-att-src="kanban_gravatar(record.user_email.value, 22)" class="oe_kanban_gravatar" t-att-title="record.user_id.value"/></td>
|
||||
<td valign="top" width="22">
|
||||
<img t-att-src="kanban_image('res.users', 'avatar', record.user_id.raw_value[0])" t-att-title="record.user_id.value"
|
||||
width="22" height="22" class="oe_kanban_gravatar"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
+39
-4
@@ -19,9 +19,12 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
import logging
|
||||
import addons
|
||||
import io
|
||||
import logging
|
||||
from osv import fields, osv
|
||||
from PIL import Image
|
||||
import StringIO
|
||||
|
||||
class hr_employee_category(osv.osv):
|
||||
|
||||
@@ -145,6 +148,34 @@ class hr_employee(osv.osv):
|
||||
_name = "hr.employee"
|
||||
_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):
|
||||
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)
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
'country_id': fields.many2one('res.country', 'Nationality'),
|
||||
'birthday': fields.date("Date of Birth"),
|
||||
@@ -170,7 +201,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': fields.binary('Photo'),
|
||||
'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_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'),
|
||||
@@ -217,7 +252,7 @@ class hr_employee(osv.osv):
|
||||
|
||||
def _get_photo(self, cr, uid, context=None):
|
||||
photo_path = addons.get_module_resource('hr','images','photo.png')
|
||||
return open(photo_path, 'rb').read().encode('base64')
|
||||
return self._photo_resize(cr, uid, open(photo_path, 'rb').read().encode('base64'), context=context)
|
||||
|
||||
_defaults = {
|
||||
'active': 1,
|
||||
|
||||
+10
-10
File diff suppressed because one or more lines are too long
@@ -34,7 +34,7 @@
|
||||
<field name="parent_id" />
|
||||
</group>
|
||||
<group colspan="2" col="1">
|
||||
<field name="photo" widget='image' nolabel="1"/>
|
||||
<field name="photo" widget='image' nolabel="1" on_change="onchange_photo(photo)"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook colspan="6">
|
||||
@@ -131,7 +131,6 @@
|
||||
<field name="model">hr.employee</field>
|
||||
<field name="type">kanban</field>
|
||||
<field name="arch" type="xml">
|
||||
|
||||
<kanban>
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
|
||||
@@ -437,7 +437,8 @@
|
||||
<field name="name"/>
|
||||
</td>
|
||||
<td valign="top" width="22">
|
||||
<img t-att-src="kanban_gravatar(record.user_email.value, 22)" class="oe_kanban_gravatar" t-att-title="record.user_id.value"/>
|
||||
<img t-att-src="kanban_image('res.users', 'avatar', record.user_id.raw_value[0])" t-att-title="record.user_id.value"
|
||||
width="22" height="22" class="oe_kanban_gravatar"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user