diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index 67f09faf9c4..2385983f020 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -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'), }