[FIX] code cleanup (addon hr_holidays)

improves th _leaves_count method, and remove an useless one2many field
(leaves_ids)

bzr revid: ged@openerp.com-20140507083556-rqm5sllj8fc3qfev
This commit is contained in:
Gery Debongnie 2014-05-07 10:35:56 +02:00
parent b08e0b0fe1
commit cc041c516a
1 changed files with 5 additions and 8 deletions

View File

@ -550,13 +550,11 @@ class hr_employee(osv.osv):
return result
def _leaves_count(self, cr, uid, ids, field_name, arg, context=None):
res = dict(map(lambda x: (x,0), ids))
try:
for employee in self.browse(cr, uid, ids, context=context):
res[employee.id] = len(employee.leave_ids)
except:
pass
return res
Holidays = self.pool['hr.holidays']
return {
employee_id: Holidays.search_count(cr,uid, [('employee_id', '=', employee_id)], context=context)
for employee_id in ids
}
_columns = {
'remaining_leaves': fields.function(_get_remaining_days, string='Remaining Legal Leaves', fnct_inv=_set_remaining_days, type="float", help='Total number of legal leaves allocated to this employee, change this value to create allocation/leave request. Total based on all the leave types without overriding limit.'),
@ -566,7 +564,6 @@ class hr_employee(osv.osv):
'current_leave_id': fields.function(_get_leave_status, multi="leave_status", string="Current Leave Type",type='many2one', relation='hr.holidays.status'),
'leave_date_from': fields.function(_get_leave_status, multi='leave_status', type='date', string='From Date'),
'leave_date_to': fields.function(_get_leave_status, multi='leave_status', type='date', string='To Date'),
'leave_ids': fields.one2many('hr.holidays', 'employee_id', 'Leaves'),
'leaves_count': fields.function(_leaves_count, type='integer', string='Leaves'),
}