Skip to content

Commit

Permalink
fix: shift not fetched in checkin on holidays
Browse files Browse the repository at this point in the history
(cherry picked from commit df96e1a)
  • Loading branch information
ruchamahabal authored and mergify[bot] committed May 2, 2023
1 parent 7a2c9c8 commit e47932a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 49 deletions.
30 changes: 0 additions & 30 deletions hrms/hr/doctype/employee_checkin/test_employee_checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,36 +258,6 @@ def test_fetch_shift_spanning_over_two_days(self):
self.assertEqual(log.shift_actual_start, datetime.combine(prev_day, get_time("22:00:00")))
self.assertEqual(log.shift_actual_end, datetime.combine(date, get_time("02:00:00")))

def test_no_shift_fetched_on_holiday_as_per_shift_holiday_list(self):
date = getdate()
from_date = get_year_start(date)
to_date = get_year_ending(date)
holiday_list = make_holiday_list(from_date=from_date, to_date=to_date)

employee = make_employee("[email protected]", company="_Test Company")
setup_shift_type(shift_type="Test Holiday Shift", holiday_list=holiday_list)

first_sunday = get_first_sunday(holiday_list, for_date=date)
timestamp = datetime.combine(first_sunday, get_time("08:00:00"))
log = make_checkin(employee, timestamp)

self.assertIsNone(log.shift)

@set_holiday_list("Salary Slip Test Holiday List", "_Test Company")
def test_no_shift_fetched_on_holiday_as_per_employee_holiday_list(self):
employee = make_employee("[email protected]", company="_Test Company")
shift_type = setup_shift_type(shift_type="Test Holiday Shift")
shift_type.holiday_list = None
shift_type.save()

date = getdate()

first_sunday = get_first_sunday(self.holiday_list, for_date=date)
timestamp = datetime.combine(first_sunday, get_time("08:00:00"))
log = make_checkin(employee, timestamp)

self.assertIsNone(log.shift)

def test_consecutive_shift_assignments_overlapping_within_grace_period(self):
# test adjustment for start and end times if they are overlapping
# within "begin_check_in_before_shift_start_time" and "allow_check_out_after_shift_end_time" periods
Expand Down
20 changes: 1 addition & 19 deletions hrms/hr/doctype/shift_assignment/shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
from frappe.query_builder import Criterion
from frappe.utils import cstr, get_datetime, get_link_to_form, get_time, getdate, now_datetime

from erpnext.setup.doctype.employee.employee import get_holiday_list_for_employee
from erpnext.setup.doctype.holiday_list.holiday_list import is_holiday

from hrms.hr.utils import validate_active_employee


Expand Down Expand Up @@ -276,7 +273,7 @@ def get_employee_shift(
consider_default_shift: bool = False,
next_shift_direction: str = None,
) -> Dict:
"""Returns a Shift Type for the given employee on the given date. (excluding the holidays)
"""Returns a Shift Type for the given employee on the given date
:param employee: Employee for which shift is required.
:param for_timestamp: DateTime on which shift is required
Expand All @@ -293,10 +290,6 @@ def get_employee_shift(
if not shift_details and consider_default_shift:
shift_details = get_shift_details(default_shift, for_timestamp)

# if its a holiday, reset
if shift_details and is_holiday_date(employee, shift_details):
shift_details = None

# if no shift is found, find next or prev shift assignment based on direction
if not shift_details and next_shift_direction:
shift_details = get_prev_or_next_shift(
Expand Down Expand Up @@ -354,17 +347,6 @@ def get_prev_or_next_shift(
return shift_details or {}


def is_holiday_date(employee: str, shift_details: Dict) -> bool:
holiday_list_name = frappe.db.get_value(
"Shift Type", shift_details.shift_type.name, "holiday_list"
)

if not holiday_list_name:
holiday_list_name = get_holiday_list_for_employee(employee, False)

return holiday_list_name and is_holiday(holiday_list_name, shift_details.start_datetime.date())


def get_employee_shift_timings(
employee: str, for_timestamp: datetime = None, consider_default_shift: bool = False
) -> List[Dict]:
Expand Down

0 comments on commit e47932a

Please sign in to comment.