[IMP] Updated after changes in server user_img branch. Also updated hr photo management and comments, according to review of server branch.
bzr revid: tde@openerp.com-20120323100439-qpirgrt2my68z046
This commit is contained in:
parent
2b82ecc930
commit
096316f19e
|
@ -305,7 +305,7 @@
|
|||
</t>
|
||||
</td>
|
||||
<td valign="top" width="22">
|
||||
<img t-att-src="kanban_image('res.users', 'avatar_mini', record.user_id.raw_value[0])" 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>
|
||||
|
|
|
@ -149,27 +149,25 @@ class hr_employee(osv.osv):
|
|||
_description = "Employee"
|
||||
_inherits = {'resource.resource': "resource_id"}
|
||||
|
||||
def onchange_photo_mini(self, cr, uid, ids, value, context=None):
|
||||
return {'value': {'photo': value, 'photo_mini': self._photo_resize(cr, uid, value) } }
|
||||
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) } }
|
||||
|
||||
def _set_photo_mini(self, cr, uid, id, name, value, args, context=None):
|
||||
return self.write(cr, uid, [id], {'photo': 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)
|
||||
|
||||
def _photo_resize(self, cr, uid, photo, context=None):
|
||||
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((180, 150), Image.ANTIALIAS)
|
||||
img.thumbnail((heigth, width), Image.ANTIALIAS)
|
||||
img_stream = StringIO.StringIO()
|
||||
img.save(img_stream, "JPEG")
|
||||
return img_stream.getvalue().encode('base64')
|
||||
|
||||
def _get_photo_mini(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
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 not hr_empl.photo:
|
||||
result[hr_empl.id] = False
|
||||
else:
|
||||
result[hr_empl.id] = self._photo_resize(cr, uid, hr_empl.photo, context=context)
|
||||
if hr_empl.photo_stored:
|
||||
result[hr_empl.id] = self._photo_resize(cr, uid, hr_empl.photo_stored, context=context)
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
|
@ -197,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': fields.binary('Photo'),
|
||||
'photo_mini': fields.function(_get_photo_mini, fnct_inv=_set_photo_mini, string='Photo Mini', type="binary",
|
||||
'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': fields.function(_get_photo, fnct_inv=_set_photo, string='Employee photo', type="binary",
|
||||
store = {
|
||||
'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10),
|
||||
}),
|
||||
'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."),
|
||||
'passport_id':fields.char('Passport No', size=64),
|
||||
'color': fields.integer('Color Index'),
|
||||
'city': fields.related('address_id', 'city', type='char', string='City'),
|
||||
|
@ -248,11 +246,11 @@ class hr_employee(osv.osv):
|
|||
|
||||
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'))
|
||||
return self._photo_resize(cr, uid, open(photo_path, 'rb').read().encode('base64'), context=context)
|
||||
|
||||
_defaults = {
|
||||
'active': 1,
|
||||
'photo_mini': _get_photo,
|
||||
'photo': _get_photo,
|
||||
'marital': 'single',
|
||||
'color': 0,
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<field name="parent_id" />
|
||||
</group>
|
||||
<group colspan="2" col="1">
|
||||
<field name="photo_mini" widget='image' nolabel="1" on_change="onchange_photo_mini(photo_mini)"/>
|
||||
<field name="photo" widget='image' nolabel="1" on_change="onchange_photo(photo)"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook colspan="6">
|
||||
|
@ -136,7 +136,7 @@
|
|||
<t t-name="kanban-box">
|
||||
<div class="oe_employee_vignette">
|
||||
<div class="oe_employee_image">
|
||||
<a type="edit"><img t-att-src="kanban_image('hr.employee', 'photo_mini', record.id.value)" class="oe_employee_picture"/></a>
|
||||
<a type="edit"><img t-att-src="kanban_image('hr.employee', 'photo', record.id.value)" class="oe_employee_picture"/></a>
|
||||
</div>
|
||||
<div class="oe_employee_details">
|
||||
<h4><a type="edit"><field name="name"/> (<field name="login"/>)</a></h4>
|
||||
|
|
|
@ -354,7 +354,7 @@
|
|||
<field name="name"/>
|
||||
</td>
|
||||
<td valign="top" width="22">
|
||||
<img t-att-src="kanban_image('res.users', 'avatar_mini', record.user_id.raw_value[0])" 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>
|
||||
|
|
Loading…
Reference in New Issue