image_stream = io.BytesIO(obj.photo.decode('base64'))
img = Image.open(image_stream)
- img.thumbnail((120, 100), Image.ANTIALIAS)
+ img.thumbnail((180, 150), Image.ANTIALIAS)
img_stream = StringIO.StringIO()
img.save(img_stream, "JPEG")
result[obj.id] = img_stream.getvalue().encode('base64')
return result
+ def _set_photo_mini(self, cr, uid, id, name, value, args, context=None):
+ self.write(cr, uid, [id], {'photo': value}, context=context)
+ return True
+
_columns = {
'country_id': fields.many2one('res.country', 'Nationality'),
'birthday': fields.date("Date of Birth"),
'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, string='Photo Mini', type="binary",
+ 'photo_mini': fields.function(_get_photo_mini, fnct_inv=_set_photo_mini, string='Photo Mini', type="binary",
store = {
- 'hr.epployee': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10),
+ 'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10),
}),
'passport_id':fields.char('Passport No', size=64),
'color': fields.integer('Color Index'),
return user_id
- def _get_photo_calc(self, cr, uid, ids, name, args, context=None):
- result = {}
- empl_obj = self.pool.get('hr.employee')
- for user in self.browse(cr, uid, ids, context=context):
- result[user.id] = user.photo
- if user.hr_photo_prior:
- empl_ids = empl_obj.search(cr, uid, [('user_id', '=', user.id)], context=context)
- if empl_ids:
- empl = empl_obj.browse(cr, uid, empl_ids, context=context)[0]
- result[user.id] = empl.photo
- return result
-
- def _get_photo_calc_mini(self, cr, uid, ids, name, args, context=None):
- result = {}
- empl_obj = self.pool.get('hr.employee')
- for user in self.browse(cr, uid, ids, context=context):
- result[user.id] = user.photo_mini
- if user.hr_photo_prior:
- empl_ids = empl_obj.search(cr, uid, [('user_id', '=', user.id)], context=context)
- if empl_ids:
- empl = empl_obj.browse(cr, uid, empl_ids, context=context)[0]
- result[user.id] = empl.photo_mini
- return result
-
- _columns = {
- 'hr_photo_prior': fields.boolean('Use employee photo'),
- 'photo_calc': fields.function(_get_photo_calc, string='Photo', type="binary", readonly=True),
- 'photo_calc_mini': fields.function(_get_photo_calc_mini, string='Photo Mini', type="binary", readonly=True),
- }
-
res_users()
<field name="parent_id" />
</group>
<group colspan="2" col="1">
- <field name="photo" widget='image' nolabel="1"/>
+ <field name="photo_mini" widget='image' nolabel="1"/>
</group>
</group>
<notebook colspan="6">
<field name="res_id" ref="hr.menu_open_view_employee_list_my"/>
</record>
- <!-- add photo option in res.users -->
- <record id="view_users_form_hr_photo" model="ir.ui.view">
- <field name="name">res.users.form_hr_photo</field>
- <field name="model">res.users</field>
- <field name="type">form</field>
- <field name="inherit_id" ref="base.view_users_form"/>
- <field name="arch" type="xml">
- <field name="photo" widget='image' nolabel="1" colspan="2" position="replace">
- <field name="photo" widget='image' nolabel="1" colspan="2" attrs="{'invisible': [('hr_photo_prior','=',True)]}"/>
- <field name="photo_calc" widget='image' nolabel="1" colspan="2" attrs="{'invisible': [('hr_photo_prior','=',False)]}"/>
- </field>
- <group name="gr_photo" col="2" colspan="1" position="inside">
- <field name="hr_photo_prior" colspan="2"/>
- </group>
- </field>
- </record>
-
<!--
=======================
Employee architecture