forked from frappe/erpnext
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Shift Type): fix all test dependency to shift type
- Loading branch information
1 parent
2c457c0
commit 3f9d64e
Showing
4 changed files
with
48 additions
and
21 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
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 |
---|---|---|
|
@@ -44,12 +44,15 @@ def test_mark_attendance(self): | |
log_out = make_checkin(employee, timestamp) | ||
self.assertEqual(log_out.shift, shift_type.name) | ||
|
||
|
||
shift_type.process_auto_attendance() | ||
|
||
attendance = frappe.db.get_value( | ||
"Attendance", {"shift": shift_type.name,"attendance_date":date}, ["status", "name"], as_dict=True | ||
) | ||
|
||
self.assertEqual(attendance.status, "Present") | ||
|
||
|
||
def test_entry_and_exit_grace(self): | ||
from erpnext.hr.doctype.employee_checkin.test_employee_checkin import make_checkin | ||
|
@@ -71,10 +74,12 @@ def test_entry_and_exit_grace(self): | |
log_in = make_checkin(employee, timestamp) | ||
self.assertEqual(log_in.shift, shift_type.name) | ||
|
||
|
||
timestamp = datetime.combine(date, get_time("10:30:00")) | ||
log_out = make_checkin(employee, timestamp) | ||
self.assertEqual(log_out.shift, shift_type.name) | ||
|
||
|
||
shift_type.process_auto_attendance() | ||
|
||
attendance = frappe.db.get_value( | ||
|
@@ -108,8 +113,10 @@ def test_working_hours_threshold_for_half_day(self): | |
attendance = frappe.db.get_value( | ||
"Attendance", {"shift": shift_type.name,"attendance_date":date}, ["status", "working_hours"], as_dict=True | ||
) | ||
|
||
self.assertEqual(attendance.status, "Half Day") | ||
self.assertEqual(attendance.working_hours, 1.5) | ||
|
||
|
||
def test_working_hours_threshold_for_absent(self): | ||
from erpnext.hr.doctype.employee_checkin.test_employee_checkin import make_checkin | ||
|
@@ -122,18 +129,19 @@ def test_working_hours_threshold_for_absent(self): | |
timestamp = datetime.combine(date, get_time("08:00:00")) | ||
log_in = make_checkin(employee, timestamp) | ||
self.assertEqual(log_in.shift, shift_type.name) | ||
|
||
timestamp = datetime.combine(date, get_time("09:30:00")) | ||
log_out = make_checkin(employee, timestamp) | ||
self.assertEqual(log_out.shift, shift_type.name) | ||
|
||
shift_type.process_auto_attendance() | ||
|
||
attendance = frappe.db.get_value( | ||
"Attendance", {"shift": shift_type.name,"attendance_date":date}, ["status", "working_hours"], as_dict=True | ||
) | ||
self.assertEqual(attendance.status, "Absent") | ||
self.assertEqual(attendance.working_hours, 1.5) | ||
|
||
|
||
def test_working_hours_threshold_for_absent_and_half_day_1(self): | ||
# considers half day over absent | ||
|
@@ -145,6 +153,7 @@ def test_working_hours_threshold_for_absent_and_half_day_1(self): | |
working_hours_threshold_for_half_day=1, | ||
working_hours_threshold_for_absent=2, | ||
) | ||
|
||
date = getdate() | ||
make_shift_assignment(shift_type.name, employee, date) | ||
|
||
|
@@ -161,9 +170,11 @@ def test_working_hours_threshold_for_absent_and_half_day_1(self): | |
attendance = frappe.db.get_value( | ||
"Attendance", {"shift": shift_type.name,"attendance_date":date}, ["status", "working_hours"], as_dict=True | ||
) | ||
|
||
self.assertEqual(attendance.status, "Half Day") | ||
self.assertEqual(attendance.working_hours, 0.75) | ||
|
||
|
||
def test_working_hours_threshold_for_absent_and_half_day_2(self): | ||
# considers absent over half day | ||
from erpnext.hr.doctype.employee_checkin.test_employee_checkin import make_checkin | ||
|
@@ -180,7 +191,7 @@ def test_working_hours_threshold_for_absent_and_half_day_2(self): | |
timestamp = datetime.combine(date, get_time("08:00:00")) | ||
log_in = make_checkin(employee, timestamp) | ||
self.assertEqual(log_in.shift, shift_type.name) | ||
|
||
timestamp = datetime.combine(date, get_time("09:30:00")) | ||
log_out = make_checkin(employee, timestamp) | ||
self.assertEqual(log_out.shift, shift_type.name) | ||
|
@@ -201,8 +212,9 @@ def test_mark_absent_for_dates_with_no_attendance(self): | |
shift_type.process_auto_attendance() | ||
|
||
attendance = frappe.db.get_value( | ||
"Attendance", {"attendance_date": date, "employee": employee}, "status" | ||
"Attendance", {"employee": employee}, "status" | ||
) | ||
|
||
self.assertEqual(attendance, "Absent") | ||
|
||
@set_holiday_list("Salary Slip Test Holiday List", "_Test Company") | ||
|
@@ -231,7 +243,7 @@ def test_get_start_and_end_dates(self): | |
date = getdate() | ||
|
||
doj = add_days(date, -30) | ||
relieving_date = add_days(date, -6) | ||
relieving_date = add_days(date, -5) | ||
employee = make_employee( | ||
"[email protected]", | ||
company="_Test Company", | ||
|
@@ -241,6 +253,7 @@ def test_get_start_and_end_dates(self): | |
shift_type = setup_shift_type( | ||
shift_type="Test Absent with no Attendance", process_attendance_after=add_days(doj, 2) | ||
) | ||
|
||
make_shift_assignment(shift_type.name, employee, add_days(date, -25)) | ||
|
||
shift_type.process_auto_attendance() | ||
|
@@ -254,6 +267,7 @@ def test_get_start_and_end_dates(self): | |
attendance = frappe.db.get_value( | ||
"Attendance", {"attendance_date": relieving_date, "employee": employee}, "status" | ||
) | ||
|
||
self.assertEquals(attendance, "Absent") | ||
|
||
# should not mark absent after Relieving Date | ||
|
@@ -279,11 +293,11 @@ def test_skip_auto_attendance_for_duplicate_record(self): | |
timestamp = datetime.combine(date, get_time("08:00:00")) | ||
log_in = make_checkin(employee, timestamp) | ||
self.assertEqual(log_in.shift, shift_type.name) | ||
|
||
|
||
|
||
timestamp = datetime.combine(date, get_time("12:00:00")) | ||
log_out = make_checkin(employee, timestamp) | ||
self.assertEqual(log_out.shift, shift_type.name) | ||
|
||
# auto attendance should skip marking | ||
shift_type.process_auto_attendance() | ||
|
||
|
@@ -312,7 +326,7 @@ def test_skip_auto_attendance_for_overlapping_shift(self): | |
timestamp = datetime.combine(date, get_time("09:30:00")) | ||
log_in = make_checkin(employee, timestamp) | ||
self.assertEqual(log_in.shift, shift_2.name) | ||
|
||
timestamp = datetime.combine(date, get_time("11:00:00")) | ||
log_out = make_checkin(employee, timestamp) | ||
self.assertEqual(log_out.shift, shift_2.name) | ||
|
@@ -347,10 +361,11 @@ def setup_shift_type(**args): | |
"days":[ | ||
{"day":"Sunday"}, | ||
{"day":"Monday"}, | ||
{"day":"Tuesday"},], | ||
{"day":"Tuesday"}, | ||
{"day":"Wednesday"}, | ||
{"day":"Thursday"}], | ||
} | ||
) | ||
|
||
holiday_list = "Employee Checkin Test Holiday List" | ||
if not frappe.db.exists("Holiday List", "Employee Checkin Test Holiday List"): | ||
holiday_list = frappe.get_doc( | ||
|
@@ -366,10 +381,8 @@ def setup_shift_type(**args): | |
shift_type.holiday_list = holiday_list | ||
shift_type.update(args) | ||
shift_type.save() | ||
|
||
return shift_type | ||
|
||
|
||
|
||
def make_shift_assignment(shift_type, employee, start_date, end_date=None): | ||
shift_assignment = frappe.get_doc( | ||
{ | ||
|
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 |
---|---|---|
|
@@ -32,7 +32,8 @@ def test_monthly_attendance_sheet_report(self): | |
now = now_datetime() | ||
previous_month = now.month - 1 | ||
previous_month_first = now.replace(day=1).replace(month=previous_month).date() | ||
|
||
self.employee = make_employee("[email protected]", company="_Test Company") | ||
|
||
company = frappe.db.get_value("Employee", self.employee, "company") | ||
|
||
# mark different attendance status on first 3 days of previous month | ||
|
@@ -66,6 +67,7 @@ def test_monthly_attendance_sheet_with_detailed_view(self): | |
now = now_datetime() | ||
previous_month = now.month - 1 | ||
previous_month_first = now.replace(day=1).replace(month=previous_month).date() | ||
self.employee = make_employee("[email protected]", company="_Test Company") | ||
|
||
company = frappe.db.get_value("Employee", self.employee, "company") | ||
|
||
|
@@ -104,6 +106,7 @@ def test_monthly_attendance_sheet_with_summarized_view(self): | |
now = now_datetime() | ||
previous_month = now.month - 1 | ||
previous_month_first = now.replace(day=1).replace(month=previous_month).date() | ||
self.employee = make_employee("[email protected]", company="_Test Company") | ||
|
||
company = frappe.db.get_value("Employee", self.employee, "company") | ||
|
||
|
@@ -150,7 +153,8 @@ def test_monthly_attendance_sheet_with_summarized_view(self): | |
@set_holiday_list("Salary Slip Test Holiday List", "_Test Company") | ||
def test_attendance_with_group_by_filter(self): | ||
from erpnext.hr.doctype.shift_type.test_shift_type import setup_shift_type | ||
setup_shift_type(shift_type="Day Shift") | ||
setup_shift_type() | ||
self.employee = make_employee("[email protected]", company="_Test Company") | ||
now = now_datetime() | ||
previous_month = now.month - 1 | ||
previous_month_first = now.replace(day=1).replace(month=previous_month).date() | ||
|
@@ -191,6 +195,7 @@ def test_attendance_with_employee_filter(self): | |
now = now_datetime() | ||
previous_month = now.month - 1 | ||
previous_month_first = now.replace(day=1).replace(month=previous_month).date() | ||
self.employee = make_employee("[email protected]", company="_Test Company") | ||
|
||
company = frappe.db.get_value("Employee", self.employee, "company") | ||
|
||
|