Skip to content

Commit

Permalink
Merge pull request #2665 from frappe/mergify/bp/version-14-hotfix/pr-…
Browse files Browse the repository at this point in the history
…2602

fix: mark absence for default shift on non-overlapping dates if another shift assignment exists (backport #2602)
  • Loading branch information
asmitahase authored Jan 20, 2025
2 parents d4976f9 + 20796be commit 1d412a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hrms/hr/doctype/shift_type/shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,16 @@ def get_assigned_employees(self, from_date=None, consider_default_shift=False) -
assigned_employees = frappe.get_all("Shift Assignment", filters=filters, pluck="employee")

if consider_default_shift:
default_shift_employees = self.get_employees_with_default_shift(filters)
default_shift_employees = self.get_employees_with_default_shift(filters, from_date)
assigned_employees = set(assigned_employees + default_shift_employees)

# exclude inactive employees
inactive_employees = frappe.db.get_all("Employee", {"status": "Inactive"}, pluck="name")

return list(set(assigned_employees) - set(inactive_employees))

def get_employees_with_default_shift(self, filters: dict) -> list:
def get_employees_with_default_shift(self, filters: dict, from_date) -> list:
filters["start_date"] = ("<=", from_date)
default_shift_employees = frappe.get_all(
"Employee", filters={"default_shift": self.name, "status": "Active"}, pluck="name"
)
Expand All @@ -259,6 +260,7 @@ def get_employees_with_default_shift(self, filters: dict) -> list:
return []

# exclude employees from default shift list if any other valid shift assignment exists
# that starts before the attendance processing date
del filters["shift_type"]
filters["employee"] = ("in", default_shift_employees)

Expand Down
21 changes: 21 additions & 0 deletions hrms/hr/doctype/shift_type/test_shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,27 @@ def test_skip_auto_attendance_for_overlapping_shift(self):
self.assertEqual(log_in.skip_auto_attendance, 1)
self.assertEqual(log_out.skip_auto_attendance, 1)

def test_mark_attendance_for_default_shift_when_shift_assignment_is_not_overlapping(self):
shift_1 = setup_shift_type(shift_type="Deafult Shift", start_time="08:00:00", end_time="12:00:00")
shift_2 = setup_shift_type(shift_type="Not Default Shift", start_time="10:00:00", end_time="18:00:00")
employee = make_employee(
"[email protected]", company="_Test Company", default_shift=shift_1.name
)
shift_assigned_date = add_days(getdate(), +1)
make_shift_assignment(shift_2.name, employee, shift_assigned_date)
from hrms.hr.doctype.attendance.attendance import mark_attendance

mark_attendance(employee, add_days(getdate(), -1), "Present", shift=shift_1.name)
shift_1.process_auto_attendance()
self.assertEqual(
frappe.db.get_value(
"Attendance",
{"employee": employee, "attendance_date": getdate(), "shift": shift_1.name},
"status",
),
"Absent",
)


def setup_shift_type(**args):
args = frappe._dict(args)
Expand Down

0 comments on commit 1d412a9

Please sign in to comment.