From 30384249e11d1d74b19bf2b63d4fd9fe6a99bad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Thu, 16 Feb 2017 15:03:17 +0100 Subject: [PATCH] [ADD] project_timesheet_holidays: generate timesheet when on leaves This commit proposes to allow to automatically generate timesheet lines when an employee is on leaves. Project and task used for timesheeting is globally configured on the company. Holidays type choose whether to generate timesheets or not and take the company default configuration. When an HR officer validates a leave request, analytic lines will be generated for each day off. The unit amount will be based on the working calendar of the employee taking the leave. Generated timesheet lines are attached to the project and task configured on the holidays type. Configuring timesheet lines generation at holiday type level allows to tune the use of leave requests. You may have for example "home working" holiday type that should not generate timesheets while "legal leaves" should. --- addons/hr_holidays/models/hr_holidays.py | 14 ++-- .../hr_holidays/views/hr_holidays_views.xml | 31 +++++---- .../hr_timesheet_config_settings.py | 1 + .../hr_timesheet_config_settings_views.xml | 20 ++++++ addons/project_timesheet_holidays/__init__.py | 4 ++ .../__manifest__.py | 24 +++++++ .../models/__init__.py | 7 ++ .../models/account_analytic.py | 17 +++++ .../models/hr_holidays.py | 64 +++++++++++++++++++ .../models/res_company.py | 49 ++++++++++++++ .../models/res_config.py | 11 ++++ .../views/hr_holidays_views.xml | 19 ++++++ .../views/res_config_views.xml | 26 ++++++++ 13 files changed, 271 insertions(+), 16 deletions(-) create mode 100644 addons/project_timesheet_holidays/__init__.py create mode 100644 addons/project_timesheet_holidays/__manifest__.py create mode 100644 addons/project_timesheet_holidays/models/__init__.py create mode 100644 addons/project_timesheet_holidays/models/account_analytic.py create mode 100644 addons/project_timesheet_holidays/models/hr_holidays.py create mode 100644 addons/project_timesheet_holidays/models/res_company.py create mode 100644 addons/project_timesheet_holidays/models/res_config.py create mode 100644 addons/project_timesheet_holidays/views/hr_holidays_views.xml create mode 100644 addons/project_timesheet_holidays/views/res_config_views.xml diff --git a/addons/hr_holidays/models/hr_holidays.py b/addons/hr_holidays/models/hr_holidays.py index 083d0d4e15a..eff33ce5af3 100644 --- a/addons/hr_holidays/models/hr_holidays.py +++ b/addons/hr_holidays/models/hr_holidays.py @@ -471,10 +471,7 @@ class Holidays(models.Model): else: holiday.write({'first_approver_id': current_employee.id}) if holiday.holiday_type == 'employee' and holiday.type == 'remove': - meeting_values = holiday._prepare_holidays_meeting_values() - meeting = self.env['calendar.event'].with_context(no_mail_to_attendees=True).create(meeting_values) - holiday._create_resource_leave() - holiday.write({'meeting_id': meeting.id}) + holiday._validate_leave_request() elif holiday.holiday_type == 'category': leaves = self.env['hr.holidays'] for employee in holiday.category_id.employee_ids: @@ -486,6 +483,15 @@ class Holidays(models.Model): leaves.action_validate() return True + def _validate_leave_request(self): + """ Validate leave requests (holiday_type='employee' and holiday.type='remove') + by creating a calendar event and a resource leaves. """ + for holiday in self.filtered(lambda request: request.type == 'remove' and request.holiday_type == 'employee'): + meeting_values = holiday._prepare_holidays_meeting_values() + meeting = self.env['calendar.event'].with_context(no_mail_to_attendees=True).create(meeting_values) + holiday.write({'meeting_id': meeting.id}) + holiday._create_resource_leave() + @api.multi def _prepare_holidays_meeting_values(self): self.ensure_one() diff --git a/addons/hr_holidays/views/hr_holidays_views.xml b/addons/hr_holidays/views/hr_holidays_views.xml index 43ab81b739d..d7abe9f285a 100644 --- a/addons/hr_holidays/views/hr_holidays_views.xml +++ b/addons/hr_holidays/views/hr_holidays_views.xml @@ -564,19 +564,26 @@ hr.holidays.status
- - - - - + +
+ +
+ + + + + + + + + + + - - - - - - -
+
diff --git a/addons/hr_timesheet/hr_timesheet_config_settings.py b/addons/hr_timesheet/hr_timesheet_config_settings.py index db75fa4fb3a..b61c745012a 100644 --- a/addons/hr_timesheet/hr_timesheet_config_settings.py +++ b/addons/hr_timesheet/hr_timesheet_config_settings.py @@ -14,3 +14,4 @@ class HrTimesheetConfiguration(models.TransientModel): module_hr_expense = fields.Boolean("Expenses") module_hr_holidays = fields.Boolean("Leave Management") module_hr_timesheet_attendance = fields.Boolean("Attendances") + module_project_timesheet_holidays = fields.Boolean("Leaves") diff --git a/addons/hr_timesheet/hr_timesheet_config_settings_views.xml b/addons/hr_timesheet/hr_timesheet_config_settings_views.xml index 00601ba946c..9377b3359db 100644 --- a/addons/hr_timesheet/hr_timesheet_config_settings_views.xml +++ b/addons/hr_timesheet/hr_timesheet_config_settings_views.xml @@ -13,6 +13,7 @@