[IMP]hr_employee_stats_sheet:add dependecie to hr_employee_calendar_planning and identifies the planning using by a employee during a time period
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m31s
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m31s
This commit is contained in:
@@ -100,43 +100,6 @@ class HrTimesheetSheet(models.Model):
|
||||
sheet.recovery_allocation_ids.write({"state": "refuse"})
|
||||
return res
|
||||
|
||||
def _get_contracts_in_progress_during_timesheet_sheet_time_period(self):
|
||||
"""
|
||||
get the contracts which was in progress during the timesheet sheet range time
|
||||
"""
|
||||
contracts = self.env["hr.contract"].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
|
||||
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")
|
||||
% 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
|
||||
#get the ressource calendar linked to the employee
|
||||
elif self.env.company.resource_calendar_id:
|
||||
return self.env.company.resource_calendar_id
|
||||
return None
|
||||
|
||||
def _get_working_hours_per_week(self):
|
||||
"""
|
||||
Get the weekly working hours for the employee, which is defined by:
|
||||
@@ -147,7 +110,7 @@ class HrTimesheetSheet(models.Model):
|
||||
:return: limit recovery hours
|
||||
"""
|
||||
# get ressource calendar id used during the timesheet sheet time period
|
||||
ressource_calendar_id = self._get_calendar_in_progress_during_timesheet_time_period()
|
||||
ressource_calendar_id = self.employee_id._get_calendar_in_progress_during_a_time_period(self.date_start,self.date_end)
|
||||
if ressource_calendar_id:
|
||||
resource_calendar_attendance_ids = self.env[
|
||||
"resource.calendar.attendance"
|
||||
@@ -169,7 +132,7 @@ class HrTimesheetSheet(models.Model):
|
||||
:return: hours per day
|
||||
"""
|
||||
# get ressource calendar id used during the timesheet sheet time period
|
||||
ressource_calendar_id = self._get_calendar_in_progress_during_timesheet_time_period()
|
||||
ressource_calendar_id = self.employee_id._get_calendar_in_progress_during_a_time_period(self.date_start,self.date_end)
|
||||
if ressource_calendar_id:
|
||||
return ressource_calendar_id.hours_per_day
|
||||
return HOURS_PER_DAY
|
||||
|
||||
Reference in New Issue
Block a user