-
Notifications
You must be signed in to change notification settings - Fork 847
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: show validation message before changing shift start time
chore: added tests
- Loading branch information
1 parent
0ae2335
commit a68aa49
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -688,6 +688,42 @@ def test_mark_attendance_for_default_shift_when_shift_assignment_is_not_overlapp | |
"Absent", | ||
) | ||
|
||
def test_validation_for_unlinked_logs_before_changing_important_shift_configuration(self): | ||
# the important shift configuration is start time, it is used to sort logs chronologically | ||
shift = setup_shift_type(shift_type="Test Shift", start_time="10:00:00", end_time="18:00:00") | ||
employee = make_employee( | ||
"[email protected]", company="_Test Company", default_shift=shift.name | ||
) | ||
|
||
from hrms.hr.doctype.employee_checkin.test_employee_checkin import make_checkin | ||
|
||
in_time = datetime.combine(getdate(), get_time("10:00:00")) | ||
check_in = make_checkin(employee, in_time) | ||
check_in.fetch_shift() | ||
# Case 1: raise valdiation error if shift time is being changed and checkin logs exists | ||
shift.start_time = get_time("10:15:00") | ||
self.assertRaises(frappe.ValidationError, shift.save) | ||
|
||
# don't raise validation error if something else is being changed | ||
# even if checkin logs exists, it's probably fine | ||
shift.reload() | ||
shift.begin_check_in_before_shift_start_time = 120 | ||
shift.save() | ||
self.assertEqual( | ||
frappe.get_value("Shift Type", shift.name, "begin_check_in_before_shift_start_time"), 120 | ||
) | ||
out_time = datetime.combine(getdate(), get_time("18:00:00")) | ||
check_out = make_checkin(employee, out_time) | ||
check_out.fetch_shift() | ||
shift.process_auto_attendance() | ||
|
||
# Case 2: allow shift time to change if no unlinked logs exist | ||
shift.start_time = get_time("10:15:00") | ||
shift.save() | ||
self.assertEqual( | ||
get_time(frappe.get_value("Shift Type", shift.name, "start_time")), get_time("10:15:00") | ||
) | ||
|
||
|
||
def setup_shift_type(**args): | ||
args = frappe._dict(args) | ||
|