fix get_speacial_day_timing error

This commit is contained in:
blackbelts 2025-07-08 10:24:21 +03:00
parent ef34a3713d
commit 5c27143711
1 changed files with 21 additions and 3 deletions

View File

@ -412,16 +412,34 @@ class HrAttendanceTransactions(models.Model):
time_list[7] = two_sp_timing and two_sp_timing.end_sign_out or calendar.shift_two_max_sign_out time_list[7] = two_sp_timing and two_sp_timing.end_sign_out or calendar.shift_two_max_sign_out
return time_list, planed_hours return time_list, planed_hours
# def get_speacial_day_timing(self, calender, weekday, at_date, shift=None):
# sp_days = shift and calender.special_days_partcial or calender.special_days
# for spday in sp_days:
# if spday.name.lower() == weekday and ((shift and spday.shift == shift) or (not shift and True)):
# if spday.date_from and spday.date_to \
# and str(at_date) >= spday.date_from and str(at_date) <= spday.date_to:
# return spday
# elif spday.date_from and not spday.date_to and str(at_date) >= spday.date_from:
# return spday
# elif not spday.date_from and spday.date_to and str(at_date) <= spday.date_to:
# return spday
# elif not spday.date_from and not spday.date_to:
# return spday
def get_speacial_day_timing(self, calender, weekday, at_date, shift=None): def get_speacial_day_timing(self, calender, weekday, at_date, shift=None):
# Ensure at_date is a date object
if isinstance(at_date, str):
# Adjust the format string to match your date string format
at_date = datetime.strptime(at_date, "%Y-%m-%d").date()
sp_days = shift and calender.special_days_partcial or calender.special_days sp_days = shift and calender.special_days_partcial or calender.special_days
for spday in sp_days: for spday in sp_days:
if spday.name.lower() == weekday and ((shift and spday.shift == shift) or (not shift and True)): if spday.name.lower() == weekday and ((shift and spday.shift == shift) or (not shift and True)):
if spday.date_from and spday.date_to \ if spday.date_from and spday.date_to \
and str(at_date) >= spday.date_from and str(at_date) <= spday.date_to: and at_date >= spday.date_from and at_date <= spday.date_to:
return spday return spday
elif spday.date_from and not spday.date_to and str(at_date) >= spday.date_from: elif spday.date_from and not spday.date_to and at_date >= spday.date_from:
return spday return spday
elif not spday.date_from and spday.date_to and str(at_date) <= spday.date_to: elif not spday.date_from and spday.date_to and at_date <= spday.date_to:
return spday return spday
elif not spday.date_from and not spday.date_to: elif not spday.date_from and not spday.date_to:
return spday return spday