diff --git a/hr_employee_stats_sheet/__manifest__.py b/hr_employee_stats_sheet/__manifest__.py index 3d4aaf5..14bd280 100755 --- a/hr_employee_stats_sheet/__manifest__.py +++ b/hr_employee_stats_sheet/__manifest__.py @@ -1,6 +1,6 @@ { "name": "hr_employee_stats_sheet", - "version": "16.0.2.0.0", + "version": "16.0.3.0.0", "description": "Add global sheet for employee stats", "summary": "Add global sheet for employee stats", "author": "Nicolas JEUDY", @@ -15,6 +15,7 @@ "hr_timesheet", "hr_timesheet_sheet", "resource", + "hr_employee_calendar_planning", ], "data": [ "security/ir.model.access.csv", diff --git a/hr_employee_stats_sheet/models/hr_timesheet_sheet.py b/hr_employee_stats_sheet/models/hr_timesheet_sheet.py index 867a0e1..da64318 100644 --- a/hr_employee_stats_sheet/models/hr_timesheet_sheet.py +++ b/hr_employee_stats_sheet/models/hr_timesheet_sheet.py @@ -100,38 +100,29 @@ class HrTimesheetSheet(models.Model): sheet.recovery_allocation_ids.write({"state": "refuse"}) return res - def _get_contracts_in_progress_during_timesheet_sheet_time_period(self): + def _get_calendar_in_progress_during_timesheet_time_period(self): """ - get the contracts which was in progress during the timesheet sheet range time + get the ressource calendar which was used during the timesheet sheet time period """ - contracts = self.env["hr.contract"].search( + #find calendar(s) running over the duration of the timesheet + calendars = self.env["hr.employee.calendar"].search( [ ("employee_id", "=", self.employee_id.id), - ("state", "in", ("open", "close")), ("date_start", "<=", self.date_end), "|", ("date_end", "=", False), # pas de date de fin OU ("date_end", ">=", self.date_start), # date de fin après le début ], ) - return contracts - - def _get_calendar_in_progress_during_timesheet_time_period(self): - """ - get the ressource calendar which was used during the timesheet sheet time period - """ - #checks if only one contract runs over the duration of the timesheet - contracts = self._get_contracts_in_progress_during_timesheet_sheet_time_period() - if len(contracts) > 1: - # check if a new contract start during timesheet sheet time period. If yes, raise an error + if len(calendars) > 1: raise UserError( - _("There is a contract starting during the timesheet sheet time period for the employee %s" - "Please create a new timesheet sheet starting from the new contract start date") + _("There is a calendar starting during the timesheet sheet time period for the employee %s" + "Please create a new timesheet sheet starting from the new calendar start date") % self.employee_id.display_name ) # get the ressource calendar id according to the work contract - elif self.employee_id.resource_calendar_id: - return self.employee_id.resource_calendar_id + elif calendars and calendars[0].calendar_id: + return calendars[0].calendar_id #get the ressource calendar linked to the employee elif self.env.company.resource_calendar_id: return self.env.company.resource_calendar_id