diff --git a/frontend/src/plugins/translationsPlugin.js b/frontend/src/plugins/translationsPlugin.js index 6291b84fa10..5d5778d309e 100644 --- a/frontend/src/plugins/translationsPlugin.js +++ b/frontend/src/plugins/translationsPlugin.js @@ -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) } diff --git a/hrms/hr/doctype/employee_grade/employee_grade_dashboard.py b/hrms/hr/doctype/employee_grade/employee_grade_dashboard.py index efc68ce87a3..65ade7432a4 100644 --- a/hrms/hr/doctype/employee_grade/employee_grade_dashboard.py +++ b/hrms/hr/doctype/employee_grade/employee_grade_dashboard.py @@ -2,7 +2,7 @@ def get_data(): return { "transactions": [ { - "items": ["Employee", "Leave Period"], + "items": ["Employee"], }, {"items": ["Employee Onboarding Template", "Employee Separation Template"]}, ] diff --git a/hrms/hr/doctype/shift_assignment/shift_assignment.py b/hrms/hr/doctype/shift_assignment/shift_assignment.py index 615bd501839..15b5e96b2d7 100644 --- a/hrms/hr/doctype/shift_assignment/shift_assignment.py +++ b/hrms/hr/doctype/shift_assignment/shift_assignment.py @@ -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: @@ -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: diff --git a/hrms/hr/doctype/shift_type/shift_type.json b/hrms/hr/doctype/shift_type/shift_type.json index d0651abbb2e..3f6e528bcf4 100644 --- a/hrms/hr/doctype/shift_type/shift_type.json +++ b/hrms/hr/doctype/shift_type/shift_type.json @@ -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", @@ -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", diff --git a/hrms/hr/doctype/shift_type/shift_type.py b/hrms/hr/doctype/shift_type/shift_type.py index b331ba00d4a..45125dfc5ac 100644 --- a/hrms/hr/doctype/shift_type/shift_type.py +++ b/hrms/hr/doctype/shift_type/shift_type.py @@ -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 @@ -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 @@ -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: @@ -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) @@ -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) @@ -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 ( diff --git a/hrms/hr/doctype/shift_type/test_shift_type.py b/hrms/hr/doctype/shift_type/test_shift_type.py index d8b7b0e0518..7e92da382ac 100644 --- a/hrms/hr/doctype/shift_type/test_shift_type.py +++ b/hrms/hr/doctype/shift_type/test_shift_type.py @@ -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") @@ -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() diff --git a/hrms/hr/report/employee_exits/employee_exits.json b/hrms/hr/report/employee_exits/employee_exits.json index 4fe9a853c0c..52d0d90b56f 100644 --- a/hrms/hr/report/employee_exits/employee_exits.json +++ b/hrms/hr/report/employee_exits/employee_exits.json @@ -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", diff --git a/hrms/hr/report/leave_ledger/leave_ledger.json b/hrms/hr/report/leave_ledger/leave_ledger.json index cc64cc8d158..277cae30d0a 100644 --- a/hrms/hr/report/leave_ledger/leave_ledger.json +++ b/hrms/hr/report/leave_ledger/leave_ledger.json @@ -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", diff --git a/hrms/payroll/report/income_tax_computation/income_tax_computation.json b/hrms/payroll/report/income_tax_computation/income_tax_computation.json index 7cb5b2270c0..64ce8f55e23 100644 --- a/hrms/payroll/report/income_tax_computation/income_tax_computation.json +++ b/hrms/payroll/report/income_tax_computation/income_tax_computation.json @@ -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",