hr_holidays: improvements, bug fix
bzr revid: mra@tinyerp.com-20081231095458-t82mtptmwna19p9p
This commit is contained in:
@@ -87,6 +87,31 @@ class hr_holidays(osv.osv):
|
||||
}
|
||||
_order = 'date_from desc'
|
||||
|
||||
def create(self, cr, uid, vals, *args, **kwargs):
|
||||
id_holiday = super(hr_holidays, self).create(cr, uid, vals, *args, **kwargs)
|
||||
self._create_log(cr, uid, [id_holiday])
|
||||
return id_holiday
|
||||
|
||||
def _create_log(self, cr, uid, ids):
|
||||
holidays_user_obj = self.pool.get('hr.holidays.per.user')
|
||||
list_request = []
|
||||
holidays_data = self.browse(cr, uid, ids[0])
|
||||
datas = {
|
||||
'employee_id' : holidays_data.employee_id.id,
|
||||
'name' : holidays_data.state,
|
||||
'holiday_status' : holidays_data.holiday_status.id,
|
||||
'holiday_req_id' : holidays_data.id,
|
||||
'nb_holidays' : holidays_data.number_of_days
|
||||
}
|
||||
ids_log = self.pool.get('hr.holidays.log').create(cr, uid, datas)
|
||||
ids_user_hdays = holidays_user_obj.search(cr, uid, [('employee_id', '=', holidays_data.employee_id.id),('holiday_status', '=', holidays_data.holiday_status.id)])
|
||||
for hdays in holidays_user_obj.browse(cr, uid, ids_user_hdays):
|
||||
for req in hdays.history:
|
||||
list_request.append(req.id)
|
||||
list_request.append(ids_log)
|
||||
holidays_user_obj.write(cr, uid, ids_user_hdays, {'history' : [(6,0,list_request)]})
|
||||
return True
|
||||
|
||||
def onchange_date_to(self, cr, uid, ids, date_from, date_to):
|
||||
result = {}
|
||||
if date_from:
|
||||
@@ -108,19 +133,19 @@ class hr_holidays(osv.osv):
|
||||
'state':'draft',
|
||||
'manager_id': False
|
||||
})
|
||||
self._create_log(cr, uid, ids)
|
||||
return True
|
||||
|
||||
def holidays_validate(self, cr, uid, ids, *args):
|
||||
self.check_holidays(cr,uid,ids)
|
||||
|
||||
vals = {
|
||||
'state':'validate',
|
||||
}
|
||||
ids2 = self.pool.get('hr.employee').search(cr, uid, [('user_id','=', uid)])
|
||||
if ids2:
|
||||
vals['manager_id'] = ids2[0]
|
||||
|
||||
self.write(cr, uid, ids, vals)
|
||||
self._create_log(cr, uid, ids)
|
||||
return True
|
||||
|
||||
def holidays_confirm(self, cr, uid, ids, *args):
|
||||
@@ -132,6 +157,7 @@ class hr_holidays(osv.osv):
|
||||
'state':'confirm',
|
||||
'user_id': user,
|
||||
})
|
||||
self._create_log(cr, uid, ids)
|
||||
return True
|
||||
|
||||
def holidays_refuse(self, cr, uid, ids, *args):
|
||||
@@ -140,6 +166,7 @@ class hr_holidays(osv.osv):
|
||||
'state':'refuse',
|
||||
'manager_id':ids2[0]
|
||||
})
|
||||
self._create_log(cr, uid, ids)
|
||||
return True
|
||||
|
||||
def holidays_cancel(self, cr, uid, ids, *args):
|
||||
@@ -150,17 +177,22 @@ class hr_holidays(osv.osv):
|
||||
obj_holidays_per_user=self.pool.get('hr.holidays.per.user').browse(cr, uid,holiday_id[0])
|
||||
self.pool.get('hr.holidays.per.user').write(cr,uid,obj_holidays_per_user.id,{'leaves_taken':obj_holidays_per_user.leaves_taken - record.number_of_days})
|
||||
if record.case_id:
|
||||
self.pool.get('crm.case').unlink(cr,uid,record.case_id.id)
|
||||
if record.case_id.state <> 'draft':
|
||||
raise osv.except_osv(_('Warning !'),
|
||||
_('You can not cancel this holiday request. first You have to make its case in draft state.'))
|
||||
else:
|
||||
self.pool.get('crm.case').unlink(cr,uid,[record.case_id.id])
|
||||
self.write(cr, uid, ids, {
|
||||
'state':'cancel'
|
||||
})
|
||||
|
||||
self._create_log(cr, uid, ids)
|
||||
return True
|
||||
|
||||
def holidays_draft(self, cr, uid, ids, *args):
|
||||
self.write(cr, uid, ids, {
|
||||
'state':'draft'
|
||||
})
|
||||
self._create_log(cr, uid, ids)
|
||||
return True
|
||||
|
||||
def check_holidays(self,cr,uid,ids):
|
||||
@@ -212,9 +244,17 @@ class hr_holidays_per_user(osv.osv):
|
||||
_description = "Holidays Per User"
|
||||
|
||||
def _get_remaining_leaves(self, cr, uid, ids, field_name, arg=None, context={}):
|
||||
obj_holiday = self.pool.get('hr.holidays')
|
||||
days = 0.0
|
||||
result = {}
|
||||
for r in self.read(cr, uid, ids, ['max_leaves','leaves_taken']):
|
||||
result[r['id']] = r['max_leaves'] - r['leaves_taken']
|
||||
for holiday_user in self.browse(cr, uid, ids):
|
||||
ids_request = obj_holiday.search(cr, uid, [('employee_id', '=', holiday_user.employee_id.id),('state', '=', 'validate'),('holiday_status', '=', holiday_user.holiday_status.id)])
|
||||
if ids_request:
|
||||
holidays = obj_holiday.browse(cr, uid, ids_request)
|
||||
for holiday in holidays:
|
||||
days += holiday.number_of_days
|
||||
days = holiday_user.max_leaves - days
|
||||
result[holiday_user.id] = days
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
@@ -226,6 +266,7 @@ class hr_holidays_per_user(osv.osv):
|
||||
'active' : fields.boolean('Active'),
|
||||
'notes' : fields.text('Notes'),
|
||||
'remaining_leaves': fields.function(_get_remaining_leaves, method=True, string='Remaining Leaves', type='float'),
|
||||
'history' : fields.one2many('hr.holidays.log', 'holiday_user_id', 'History')
|
||||
}
|
||||
_defaults = {
|
||||
'active' : lambda *a: True,
|
||||
@@ -239,5 +280,23 @@ class hr_holidays_per_user(osv.osv):
|
||||
|
||||
hr_holidays_per_user()
|
||||
|
||||
class holiday_user_log(osv.osv):
|
||||
_name = 'hr.holidays.log'
|
||||
_description = 'hr.holidays.log'
|
||||
_order = "holiday_req_id desc"
|
||||
_columns = {
|
||||
'name' : fields.char('Action', size=64, readonly=True),
|
||||
'holiday_req_id' : fields.char('Holiday Request ID', size=64),
|
||||
'nb_holidays' : fields.float('Number of Holidays Requested'),
|
||||
'employee_id' : fields.many2one('hr.employee', 'Employee', readonly=True),
|
||||
'holiday_status' : fields.many2one("hr.holidays.status", "Holiday's Status", readonly=True),
|
||||
'holiday_user_id' : fields.many2one('hr.holidays.per.user', 'Holidays user'),
|
||||
'date': fields.datetime('Date'),
|
||||
}
|
||||
_defaults = {
|
||||
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
}
|
||||
holiday_user_log()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<field name="model">hr.holidays</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Employee holidays">
|
||||
<form string="Employee Holidays">
|
||||
<field name="name" select="1"/>
|
||||
<field name="holiday_status" select="1"/>
|
||||
<field name="date_from" select="1"/>
|
||||
@@ -17,8 +17,8 @@
|
||||
<page string="General">
|
||||
<field name="employee_id" select="1" />
|
||||
<field name="number_of_days"/>
|
||||
<field name="notes" colspan="4"/>
|
||||
<field name="manager_id"/>
|
||||
<field name="notes" colspan="4"/>
|
||||
<newline/>
|
||||
<field name="state" select="1" colspan="2"/>
|
||||
<group colspan="2">
|
||||
@@ -36,10 +36,10 @@
|
||||
|
||||
<record model="ir.ui.view" id="view_holiday">
|
||||
<field name="name">hr.holidays.tree</field>
|
||||
<field name="model">hr.holidays</field>
|
||||
<field name="model">hr.holidays</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Employee holidays">
|
||||
<tree string="Employee Holidays">
|
||||
<field name="name"/>
|
||||
<field name="employee_id"/>
|
||||
<field name="number_of_days" string="Number of Days"/>
|
||||
@@ -51,10 +51,40 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- holidays log -->
|
||||
<record model="ir.ui.view" id="holiday_log_form">
|
||||
<field name="name">hr.holidays.log.form</field>
|
||||
<field name="model">hr.holidays.log</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Log Holidays">
|
||||
<field name="name" select="1"/>
|
||||
<field name="employee_id" select="2"/>
|
||||
<field name="holiday_status" select="1" />
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="holiday_log_tree">
|
||||
<field name="name">>hr.holidays.log.tree</field>
|
||||
<field name="model">hr.holidays.log</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Log Holidays">
|
||||
<field name="holiday_req_id" />
|
||||
<field name="date" />
|
||||
<field name="employee_id" />
|
||||
<field name="name" />
|
||||
<field name="holiday_status" />
|
||||
<field name="nb_holidays" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- holidays status -->
|
||||
<record model="ir.ui.view" id="edit_holiday_status_form">
|
||||
<field name="name">hr.holidays.status.form</field>
|
||||
<field name="model">hr.holidays.status</field>
|
||||
<field name="model">hr.holidays.status</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Define holiday status">
|
||||
@@ -68,15 +98,15 @@
|
||||
</record>
|
||||
<record model="ir.ui.view" id="view_holiday_status_tree">
|
||||
<field name="name">hr.holidays.status.tree</field>
|
||||
<field name="model">hr.holidays.status</field>
|
||||
<field name="model">hr.holidays.status</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Holiday status">
|
||||
<field name="name"/>
|
||||
<field name="color_name" />
|
||||
<field name="section_id" />
|
||||
<field name="limit" select="2"/>
|
||||
<field name="active" select="2"/>
|
||||
<field name="limit" />
|
||||
<field name="active" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -98,17 +128,24 @@
|
||||
<field name="model">hr.holidays.per.user</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Holidays Per Employee">
|
||||
<field name="employee_id" select="1" />
|
||||
<field name="holiday_status" select="1" />
|
||||
<newline/>
|
||||
<field name="max_leaves" select="2" colspan="2" />
|
||||
<field name="leaves_taken" select="2" colspan="2" />
|
||||
<newline/>
|
||||
<field name="remaining_leaves" select="2" colspan="2" />
|
||||
<field name="active" select="2"/>
|
||||
<newline/>
|
||||
<field name="notes" colspan="4" select="2"/>
|
||||
<form string="Holidays Per Employee">
|
||||
<notebook>
|
||||
<page string="General Information">
|
||||
<field name="employee_id" select="1" />
|
||||
<field name="holiday_status" select="1" />
|
||||
<newline/>
|
||||
<field name="max_leaves" select="2" />
|
||||
<field name="leaves_taken" select="2" />
|
||||
<newline/>
|
||||
<field name="remaining_leaves" select="2" colspan="2" />
|
||||
<field name="active" select="2"/>
|
||||
<newline/>
|
||||
<field name="notes" colspan="4" select="2"/>
|
||||
</page>
|
||||
<page string="History" >
|
||||
<field name="history" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
@@ -122,7 +159,7 @@
|
||||
<field name="holiday_status"/>
|
||||
<field name="max_leaves"/>
|
||||
<field name="remaining_leaves"/>
|
||||
<field name="active" select="2"/>
|
||||
<field name="active"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user