|
|
|
|
@@ -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
|
|
|
|
|
|