[IMP] hr_holidays: onchange on holiday/allocatio type
bzr revid: mra@tinyerp.com-20100510045649-kd0ui26wrde9olqp
This commit is contained in:
@@ -108,11 +108,11 @@ class hr_holidays(osv.osv):
|
||||
_description = "Holidays"
|
||||
_order = "type desc, date_from asc"
|
||||
|
||||
# def _employee_get(obj, cr, uid, context=None):
|
||||
# ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id','=', uid)])
|
||||
# if ids:
|
||||
# return ids[0]
|
||||
# return False
|
||||
def _employee_get(obj, cr, uid, context=None):
|
||||
ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id','=', uid)])
|
||||
if ids:
|
||||
return ids[0]
|
||||
return False
|
||||
|
||||
_columns = {
|
||||
'name' : fields.char('Description', required=True, readonly=True, size=64, states={'draft':[('readonly',False)]}),
|
||||
@@ -138,7 +138,7 @@ class hr_holidays(osv.osv):
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
# 'employee_id' : _employee_get ,
|
||||
'employee_id' : _employee_get ,
|
||||
'state' : 'draft',
|
||||
'type': 'remove',
|
||||
'allocation_type': 'employee',
|
||||
@@ -149,11 +149,15 @@ class hr_holidays(osv.osv):
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
if context:
|
||||
if context.has_key('type'):
|
||||
vals['type'] = context['type']
|
||||
if context.has_key('allocation_type'):
|
||||
vals['allocation_type'] = context['allocation_type']
|
||||
if 'holiday_type' in vals:
|
||||
if vals['holiday_type'] == 'employee':
|
||||
vals.update({'category_id': False})
|
||||
else:
|
||||
vals.update({'employee_id': False})
|
||||
if context.has_key('type'):
|
||||
vals['type'] = context['type']
|
||||
if context.has_key('allocation_type'):
|
||||
vals['allocation_type'] = context['allocation_type']
|
||||
return super(hr_holidays, self).create(cr, uid, vals, context=context)
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
@@ -166,6 +170,16 @@ class hr_holidays(osv.osv):
|
||||
vals.update({'employee_id': False})
|
||||
return super(hr_holidays, self).write(cr, uid, ids, vals, context=context)
|
||||
|
||||
def onchange_type(self, cr, uid, ids, holiday_type):
|
||||
result = {}
|
||||
if holiday_type=='employee':
|
||||
ids_employee = self.pool.get('hr.employee').search(cr, uid, [('user_id','=', uid)])
|
||||
if ids_employee:
|
||||
result['value'] = {
|
||||
'employee_id': ids_employee[0]
|
||||
}
|
||||
return result
|
||||
|
||||
def onchange_date_from(self, cr, uid, ids, date_to, date_from):
|
||||
result = {}
|
||||
if date_to and date_from:
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<form string="Leave Request">
|
||||
<group col="6" colspan="4">
|
||||
<field name="name" select="1"/>
|
||||
<field name="holiday_type" attrs="{'readonly':[('state','!=','draft')]}"/>
|
||||
<field name="holiday_type" on_change="onchange_type(holiday_type)" attrs="{'readonly':[('state','!=','draft')]}"/>
|
||||
</group>
|
||||
<notebook colspan="4">
|
||||
<page string="General">
|
||||
@@ -87,7 +87,7 @@
|
||||
<form string="Allocation Request">
|
||||
<field name="name" select="1"/>
|
||||
<field name="holiday_status_id" select="1" />
|
||||
<field name="holiday_type" attrs="{'readonly':[('state','!=','draft')]}" string="Allocation Type"/>
|
||||
<field name="holiday_type" on_change="onchange_type(holiday_type)" attrs="{'readonly':[('state','!=','draft')]}" string="Allocation Type"/>
|
||||
<notebook colspan="4">
|
||||
<page string="General">
|
||||
<group colspan="4" attrs="{'invisible':[('holiday_type','=','employee')]}">
|
||||
|
||||
Reference in New Issue
Block a user