diff --git a/addons/hr_holidays/__openerp__.py b/addons/hr_holidays/__openerp__.py index d6a668e00b4..32a7f5ab2a3 100644 --- a/addons/hr_holidays/__openerp__.py +++ b/addons/hr_holidays/__openerp__.py @@ -6,16 +6,16 @@ 'name': 'Leave Management', 'version': '1.5', 'category': 'Human Resources', - 'sequence': 85, + 'sequence': 27, 'summary': 'Holidays, Allocation and Leave Requests', 'website': 'https://www.odoo.com/page/employees', 'description': """ -Manage leaves and allocation requests +Manage leave requests and allocations ===================================== -This application controls the holiday schedule of your company. It allows employees to request holidays. Then, managers can review requests for holidays and approve or reject them. This way you can control the overall holiday planning for the company or department. +This application controls the leave schedule of your company. It allows employees to request leaves. Then, managers can review requests for leaves and approve or reject them. This way you can control the overall leave planning for the company or department. -You can configure several kinds of leaves (sickness, holidays, paid days, ...) and allocate leaves to an employee or department quickly using allocation requests. An employee can also make a request for more days off by making a new Allocation. It will increase the total of available days for that leave type (if the request is accepted). +You can configure several kinds of leaves (sickness, paid days, ...) and allocate leaves to an employee or department quickly using leave allocation. An employee can also make a request for more days off by making a new Leave allocation. It will increase the total of available days for that leave type (if the request is accepted). You can keep track of leaves in different ways by following reports: @@ -23,7 +23,7 @@ You can keep track of leaves in different ways by following reports: * Leaves by Department * Leaves Analysis -A synchronization with an internal agenda (Meetings of the CRM module) is also possible in order to automatically create a meeting when a holiday request is accepted by setting up a type of meeting in Leave Type. +A synchronization with an internal agenda (Meetings of the CRM module) is also possible in order to automatically create a meeting when a leave request is accepted by setting up a type of meeting in Leave Type. """, 'depends': ['hr', 'calendar', 'resource'], 'data': [ diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index fe401e6ca5a..e8e6672878c 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -77,6 +77,7 @@ class hr_holidays_status(osv.osv): 'remaining_leaves': fields.function(_user_left_days, string='Remaining Leaves', help='Maximum Leaves Allowed - Leaves Already Taken', multi='user_left_days'), 'virtual_remaining_leaves': fields.function(_user_left_days, string='Virtual Remaining Leaves', help='Maximum Leaves Allowed - Leaves Already Taken - Leaves Waiting Approval', multi='user_left_days'), 'double_validation': fields.boolean('Apply Double Validation', help="When selected, the Allocation/Leave Requests for this type require a second validation to be approved."), + 'company_id': fields.many2one('res.company', 'Company'), } _defaults = { 'color_name': 'red', @@ -227,6 +228,12 @@ class hr_holidays(osv.osv): ('date_check', "CHECK ( number_of_days_temp >= 0 )", "The number of days must be greater than 0."), ] + def name_get(self, cr, uid, ids, context=None): + res = [] + for leave in self.browse(cr, uid, ids, context=context): + res.append((leave.id, leave.name or _("%s on %s") % (leave.employee_id.name, leave.holiday_status_id.name))) + return res + def _create_resource_leave(self, cr, uid, leaves, context=None): '''This method will create entry in resource calendar leave object at the time of holidays validated ''' obj_res_leave = self.pool.get('resource.calendar.leaves') @@ -343,6 +350,10 @@ class hr_holidays(osv.osv): context = dict(context, mail_create_nolog=True) if values.get('state') and values['state'] not in ['draft', 'confirm', 'cancel'] and not self.pool['res.users'].has_group(cr, uid, 'base.group_hr_user'): raise AccessError(_('You cannot set a leave request as \'%s\'. Contact a human resource manager.') % values.get('state')) + if not values.get('name'): + employee_name = self.pool['hr.employee'].browse(cr, uid, employee_id, context=context).name + holiday_type = self.pool['hr.holidays.status'].browse(cr, uid, values.get('holiday_status_id'), context=context).name + values['name'] = _("%s on %s") % (employee_name, holiday_type) hr_holiday_id = super(hr_holidays, self).create(cr, uid, values, context=context) self.add_follower(cr, uid, [hr_holiday_id], employee_id, context=context) return hr_holiday_id @@ -390,7 +401,7 @@ class hr_holidays(osv.osv): if record.holiday_type == 'employee' and record.type == 'remove': meeting_obj = self.pool.get('calendar.event') meeting_vals = { - 'name': record.name or _('Leave Request'), + 'name': record.display_name, 'categ_ids': record.holiday_status_id.categ_id and [(6,0,[record.holiday_status_id.categ_id.id])] or [], 'duration': record.number_of_days_temp * 8, 'description': record.notes, @@ -599,15 +610,17 @@ class hr_employee(osv.Model): def _leaves_count(self, cr, uid, ids, field_name, arg, context=None): res = {} - Holidays = self.pool['hr.holidays'] - date_begin = date.today().replace(day=1) - date_end = date_begin.replace(day=calendar.monthrange(date_begin.year, date_begin.month)[1]) - for employee_id in ids: - leaves = Holidays.search_count(cr, uid, [('employee_id', '=', employee_id), ('type', '=', 'remove')], context=context) - approved_leaves = Holidays.search_count(cr, uid, [('employee_id', '=', employee_id), ('type', '=', 'remove'), ('date_from', '>=', date_begin.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)), ('date_from', '<=', date_end.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)), ('state', '=', 'validate'), ('payslip_status', '=', False)], context=context) - res[employee_id] = {'leaves_count': leaves, 'approved_leaves_count': approved_leaves} + leaves = self.pool['hr.holidays'].read_group(cr, uid, [ + ('employee_id', 'in', ids), + ('holiday_status_id.limit', '=', False), ('state', '=', 'validate')], fields=['number_of_days', 'employee_id'], groupby=['employee_id']) + res.update(dict([(leave['employee_id'][0], leave['number_of_days']) for leave in leaves ])) return res + def _show_approved_remaining_leave(self, cr, uid, ids, name, args, context=None): + if self.pool['res.users'].has_group(cr, uid, 'base.group_hr_user'): + return dict([(employee_id, True) for employee_id in ids]) + return dict([(employee.id, True) for employee in self.browse(cr, uid, ids, context=context) if employee.user_id.id == uid]) + def _absent_employee(self, cr, uid, ids, field_name, arg, context=None): today_date = datetime.datetime.utcnow().date() today_start = today_date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) # get the midnight of the current utc day @@ -643,7 +656,7 @@ class hr_employee(osv.Model): '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'), - 'leaves_count': fields.function(_leaves_count, multi='_leaves_count', type='integer', string='Number of Leaves (current month)'), - 'approved_leaves_count': fields.function(_leaves_count, multi='_leaves_count', type='integer', string='Approved Leaves not in Payslip', help="These leaves are approved but not taken into account for payslip"), + 'leaves_count': fields.function(_leaves_count, type='integer', string='Number of Leaves'), + 'show_leaves': fields.function(_show_approved_remaining_leave, type='boolean', string="Able to see Remaining Leaves"), 'is_absent_totay': fields.function(_absent_employee, fnct_search=_search_absent_employee, type="boolean", string="Absent Today", default=False) } diff --git a/addons/hr_holidays/hr_holidays_view.xml b/addons/hr_holidays/hr_holidays_view.xml index 344e530599b..8c163919479 100644 --- a/addons/hr_holidays/hr_holidays_view.xml +++ b/addons/hr_holidays/hr_holidays_view.xml @@ -22,6 +22,7 @@ + @@ -29,7 +30,7 @@ - + @@ -96,7 +97,7 @@ - +