Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
fae8912
feat(shift_type): add configurable option to mark absent on same day
iamkhanraheel Aug 11, 2026
640af15
test(shift_type): verify same-day absent marking and validation for m…
iamkhanraheel Aug 11, 2026
b69a419
feat(shift_type): generalize same-day toggle into configurable absent…
iamkhanraheel Aug 12, 2026
5c9aa0c
Merge branch 'develop' into feat/configurable_absent_marking
iamkhanraheel Aug 12, 2026
7ab006e
fix(pwa): load translations from the endpoint frappe v17 exposes
phet2 Aug 25, 2026
3e50f00
fix: mark absent for overlapping shift assignments in auto attendance
Shllokkk Aug 28, 2026
714ed9c
test: absent marking for overlapping shift assignments
Shllokkk Aug 28, 2026
619fc7e
Merge branch 'develop' into feat/configurable_absent_marking
iamkhanraheel Sep 10, 2026
1905177
Merge pull request #5091 from Shllokkk/auto-attendance-overlapping-sh…
deepeshgarg007 Sep 10, 2026
4e4438b
fix: reset hardcoded letter head on reports
Shllokkk Sep 10, 2026
1098264
Merge pull request #5248 from Shllokkk/reset-hardcoded-letter-head-on…
asmitahase Sep 10, 2026
929dd2f
Merge remote-tracking branch 'upstream/develop' into feat/configurabl…
iamkhanraheel Sep 10, 2026
76bbbee
Merge pull request #5148 from phet2/fix/pwa-translations-endpoint
deepeshgarg007 Sep 10, 2026
e1fcc36
Merge pull request #5083 from iamkhanraheel/feat/configurable_absent_…
deepeshgarg007 Sep 10, 2026
fad7c18
fix: remove Leave Period from Employee Grade connections
akhtarmohsin Sep 10, 2026
3f00f2d
Merge pull request #5254 from akhtarmohsin/fix/remove-leave-period-fr…
asmitahase Sep 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions frontend/src/plugins/translationsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ function makeTranslationFunction() {
return;
}

const url = new URL("/api/method/frappe.translate.load_all_translations", location.origin);
const url = new URL("/api/method/frappe.translate.get_boot_translations", location.origin);
url.searchParams.append("lang", window.frappe?.boot?.lang ?? navigator.language);
url.searchParams.append("hash", window.frappe?.boot?.translations_hash || window._version_number || Math.random()); // for cache busting
// url.searchParams.append("app", "hrms");
url.searchParams.append("hash", window.frappe?.boot?.translations_version || window._version_number || Math.random()); // for cache busting

try {
const response = await fetch(url);
messages = await response.json() || {}
const data = await response.json();
// whitelisted methods wrap their return value in `message`
messages = data?.message ?? data ?? {}
} catch (error) {
console.error("Failed to fetch translations:", error)
}
Expand Down
2 changes: 1 addition & 1 deletion hrms/hr/doctype/employee_grade/employee_grade_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def get_data():
return {
"transactions": [
{
"items": ["Employee", "Leave Period"],
"items": ["Employee"],
},
{"items": ["Employee Onboarding Template", "Employee Separation Template"]},
]
Expand Down
11 changes: 8 additions & 3 deletions hrms/hr/doctype/shift_assignment/shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ def get_shift_type_timing(shift_types):
return shift_timing_map


def get_shift_for_time(shifts: list[dict], for_timestamp: datetime) -> dict:
"""Returns shift with details for given timestamp"""
def get_valid_shifts_for_time(shifts: list[dict], for_timestamp: datetime) -> list[dict]:
"""Returns all shifts active at the given timestamp, sorted with overlapping timings adjusted"""
valid_shifts = []

for assignment in shifts:
Expand All @@ -316,7 +316,12 @@ def get_shift_for_time(shifts: list[dict], for_timestamp: datetime) -> dict:
valid_shifts.sort(key=lambda x: x["actual_start"])
_adjust_overlapping_shifts(valid_shifts)

return get_exact_shift(valid_shifts, for_timestamp)
return valid_shifts


def get_shift_for_time(shifts: list[dict], for_timestamp: datetime) -> dict:
"""Returns shift with details for given timestamp"""
return get_exact_shift(get_valid_shifts_for_time(shifts, for_timestamp), for_timestamp)


def _is_shift_outside_assignment_period(shift_details: dict, assignment: dict) -> bool:
Expand Down
9 changes: 9 additions & 0 deletions hrms/hr/doctype/shift_type/shift_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"begin_check_in_before_shift_start_time",
"allow_check_out_after_shift_end_time",
"mark_auto_attendance_on_holidays",
"absent_buffer_days",
"column_break_10",
"working_hours_threshold_for_half_day",
"working_hours_threshold_for_absent",
Expand Down Expand Up @@ -170,6 +171,14 @@
"fieldtype": "Check",
"label": "Mark Auto Attendance on Holidays"
},
{
"default": "1",
"description": "Number of days after the shift ends before marking Absent for missing attendance. Set to 0 to mark Absent on the same day, right after the shift's checkout window closes (requires 'Automatically update Last Sync of Checkin' to be enabled).",
"fieldname": "absent_buffer_days",
"fieldtype": "Int",
"label": "Absent Buffer (Days)",
"non_negative": 1
},
{
"default": "0",
"fieldname": "enable_late_entry_marking",
Expand Down
35 changes: 31 additions & 4 deletions hrms/hr/doctype/shift_type/shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
calculate_working_hours,
mark_attendance_and_link_log,
)
from hrms.hr.doctype.shift_assignment.shift_assignment import get_employee_shift, get_shift_details
from hrms.hr.doctype.shift_assignment.shift_assignment import (
get_employee_shift,
get_shift_details,
get_shifts_for_date,
get_valid_shifts_for_time,
)
from hrms.utils import get_date_range
from hrms.utils.holiday_list import get_holiday_dates_between

Expand All @@ -44,6 +49,7 @@ class ShiftType(Document):
if TYPE_CHECKING:
from frappe.types import DF

absent_buffer_days: DF.Int
allow_check_out_after_shift_end_time: DF.Int
allow_overtime: DF.Check
auto_update_last_sync: DF.Check
Expand Down Expand Up @@ -80,6 +86,7 @@ def validate(self):
self.validate_same_start_and_end(start, end)
self.validate_circular_shift(start, end)
self.validate_unlinked_logs()
self.validate_absent_buffer_days()

def validate_same_start_and_end(self, start_time: datetime.time, end_time: datetime.time):
if start_time == end_time:
Expand Down Expand Up @@ -136,6 +143,15 @@ def validate_unlinked_logs(self):
msg=_("Mark attendance for existing check-in/out logs before changing shift settings"),
)

def validate_absent_buffer_days(self):
if cint(self.absent_buffer_days) == 0 and not self.auto_update_last_sync:
frappe.throw(
title=_("Missing Configuration"),
msg=_("Enable {0} to mark absent on the same day").format(
frappe.bold(_("Automatically update Last Sync of Checkin"))
),
)

def is_field_modified(self, fieldname):
return not self.is_new() and self.has_value_changed(fieldname)

Expand Down Expand Up @@ -364,9 +380,15 @@ def get_start_and_end_dates(self, employee):
shift_details.actual_end if shift_details else get_datetime(self.last_sync_of_checkin)
)

# check if shift is found for 1 day before the last sync of checkin
# absentees are auto-marked 1 day after the shift to wait for any manual attendance records
prev_shift = get_employee_shift(employee, last_shift_time - timedelta(days=1), True, "reverse")
# wait `absent_buffer_days` days after the shift ends before auto-marking absent, to leave
# room for manual attendance records; 0 marks absent the same day, right after the shift ends
buffer_days = cint(self.absent_buffer_days)
ref_time = last_shift_time - timedelta(days=buffer_days)
prev_shift = get_employee_shift(employee, ref_time, True, "reverse")
if prev_shift and prev_shift.shift_type.name != self.name:
# an overlapping assignment may have won resolution; prefer this shift if also scheduled then
prev_shift = self.get_scheduled_shift_at(employee, ref_time) or prev_shift

if prev_shift and prev_shift.shift_type.name == self.name:
end_date = (
min(prev_shift.start_datetime.date(), relieving_date)
Expand All @@ -378,6 +400,11 @@ def get_start_and_end_dates(self, employee):
return None, None
return start_date, end_date

def get_scheduled_shift_at(self, employee: str, for_timestamp: datetime) -> dict | None:
"""Return this shift's details if it is validly scheduled for the employee at the given timestamp"""
shifts = get_valid_shifts_for_time(get_shifts_for_date(employee, for_timestamp), for_timestamp)
return next((shift for shift in shifts if shift.shift_type.name == self.name), None)

def get_marked_attendance_dates_between(self, employee: str, start_date: str, end_date: str) -> list[str]:
Attendance = frappe.qb.DocType("Attendance")
return (
Expand Down
98 changes: 98 additions & 0 deletions hrms/hr/doctype/shift_type/test_shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,63 @@ def test_do_not_mark_absent_before_shift_actual_end_time_for_midnight_shift(self
)
self.assertEqual(attendance, "Present")

def test_mark_absent_on_same_day(self):
employee = make_employee("test_employee_checkin@example.com", company="_Test Company")
today = getdate()

shift_type = setup_shift_type(
shift_type="Test Absent Buffer Same Day",
process_attendance_after=add_days(today, -2),
auto_update_last_sync=1,
absent_buffer_days=0,
# last sync is past today's shift actual end (12:00 + 60 min checkout buffer)
last_sync_of_checkin=datetime.combine(today, get_time("13:01:00")),
)
make_shift_assignment(shift_type.name, employee, today)

shift_type.process_auto_attendance()

attendance = frappe.db.get_value(
"Attendance", {"attendance_date": today, "employee": employee}, "status"
)
self.assertEqual(attendance, "Absent")

def test_absent_buffer_days_zero_requires_auto_update_last_sync(self):
shift_type = setup_shift_type(shift_type="Test Absent Buffer Validation", auto_update_last_sync=0)
shift_type.absent_buffer_days = 0
self.assertRaises(frappe.ValidationError, shift_type.save)

def test_mark_absent_after_two_day_buffer(self):
employee = make_employee("test_employee_checkin@example.com", company="_Test Company")
today = getdate()

shift_type = setup_shift_type(
shift_type="Test Two Day Absent Buffer",
process_attendance_after=add_days(today, -4),
absent_buffer_days=2,
last_sync_of_checkin=datetime.combine(today, get_time("15:00:00")),
)
make_shift_assignment(shift_type.name, employee, add_days(today, -4))

shift_type.process_auto_attendance()

# dates up to (today - buffer_days) should be marked absent
absent_records = frappe.get_all(
"Attendance",
{
"attendance_date": ["between", [add_days(today, -4), add_days(today, -2)]],
"employee": employee,
"status": "Absent",
},
)
self.assertEqual(len(absent_records), 3)

# dates within the buffer window should not be marked yet
for date in (add_days(today, -1), today):
self.assertIsNone(
frappe.db.get_value("Attendance", {"attendance_date": date, "employee": employee})
)

@assign_holiday_list("Salary Slip Test Holiday List", "_Test Company")
def test_skip_marking_absent_on_a_holiday(self):
employee = make_employee("test_employee_checkin@example.com", company="_Test Company")
Expand Down Expand Up @@ -663,6 +720,47 @@ def test_skip_absent_marking_for_inactive_employee(self):
attendance = frappe.db.get_value("Attendance", {"employee": employee}, "status")
self.assertIsNone(attendance)

@HRMSTestSuite.change_settings("HR Settings", {"allow_multiple_shift_assignments": 1})
def test_mark_absent_with_multiple_overlapping_shift_assignments(self):
"""Tests absent is marked for each shift when actual timings of multiple assignments overlap"""
employee = make_employee("test_employee_multishift@example.com", company="_Test Company")
today = getdate()
start_date = add_days(today, -5)
absent_date = add_days(today, -3)
last_sync = datetime.combine(today, get_time("06:00:00"))

# actual windows overlap (day: 05:00-23:00, night: 20:01-08:59) but raw timings don't
day_shift = setup_shift_type(
shift_type="Test Overlap Day",
start_time="06:00:00",
end_time="22:00:00",
process_attendance_after=start_date,
last_sync_of_checkin=last_sync,
)
night_shift = setup_shift_type(
shift_type="Test Overlap Night",
start_time="22:01:00",
end_time="05:59:00",
begin_check_in_before_shift_start_time=120,
allow_check_out_after_shift_end_time=180,
process_attendance_after=start_date,
last_sync_of_checkin=last_sync,
)

make_shift_assignment(day_shift.name, employee, start_date)
make_shift_assignment(night_shift.name, employee, start_date)

day_shift.process_auto_attendance()
night_shift.process_auto_attendance()

for shift in (day_shift, night_shift):
status = frappe.db.get_value(
"Attendance",
{"employee": employee, "shift": shift.name, "attendance_date": absent_date},
"status",
)
self.assertEqual(status, "Absent", msg=f"Absent not marked for {shift.name}")

def test_get_start_and_end_dates(self):
date = getdate()

Expand Down
2 changes: 1 addition & 1 deletion hrms/hr/report/employee_exits/employee_exits.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"filters": [],
"idx": 0,
"is_standard": "Yes",
"letter_head": "Test",
"letter_head": null,
"modified": "2021-12-05 19:47:18.332319",
"modified_by": "Administrator",
"module": "HR",
Expand Down
2 changes: 1 addition & 1 deletion hrms/hr/report/leave_ledger/leave_ledger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"filters": [],
"idx": 0,
"is_standard": "Yes",
"letter_head": "Frappe",
"letter_head": null,
"letterhead": null,
"modified": "2024-04-07 14:46:16.056637",
"modified_by": "Administrator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"filters": [],
"idx": 0,
"is_standard": "Yes",
"letter_head": "",
"letter_head": null,
"modified": "2022-02-23 13:07:30.347861",
"modified_by": "Administrator",
"module": "Payroll",
Expand Down
Loading