mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
test: fix attendance tests for unmarked days (#31205)
* test: fix attendance tests for unmarked days
* chore: remove unused import
(cherry picked from commit 536f1dfc4b)
Co-authored-by: Rucha Mahabal <ruchamahabal2@gmail.com>
This commit is contained in:
@@ -3,7 +3,15 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.tests.utils import FrappeTestCase
|
from frappe.tests.utils import FrappeTestCase
|
||||||
from frappe.utils import add_days, get_year_ending, get_year_start, getdate, now_datetime, nowdate
|
from frappe.utils import (
|
||||||
|
add_days,
|
||||||
|
add_months,
|
||||||
|
get_last_day,
|
||||||
|
get_year_ending,
|
||||||
|
get_year_start,
|
||||||
|
getdate,
|
||||||
|
nowdate,
|
||||||
|
)
|
||||||
|
|
||||||
from erpnext.hr.doctype.attendance.attendance import (
|
from erpnext.hr.doctype.attendance.attendance import (
|
||||||
get_month_map,
|
get_month_map,
|
||||||
@@ -35,63 +43,64 @@ class TestAttendance(FrappeTestCase):
|
|||||||
self.assertEqual(attendance, fetch_attendance)
|
self.assertEqual(attendance, fetch_attendance)
|
||||||
|
|
||||||
def test_unmarked_days(self):
|
def test_unmarked_days(self):
|
||||||
now = now_datetime()
|
first_sunday = get_first_sunday(
|
||||||
previous_month = now.month - 1
|
self.holiday_list, for_date=get_last_day(add_months(getdate(), -1))
|
||||||
first_day = now.replace(day=1).replace(month=previous_month).date()
|
)
|
||||||
|
attendance_date = add_days(first_sunday, 1)
|
||||||
|
|
||||||
employee = make_employee(
|
employee = make_employee(
|
||||||
"test_unmarked_days@example.com", date_of_joining=add_days(first_day, -1)
|
"test_unmarked_days@example.com", date_of_joining=add_days(attendance_date, -1)
|
||||||
)
|
)
|
||||||
frappe.db.delete("Attendance", {"employee": employee})
|
frappe.db.delete("Attendance", {"employee": employee})
|
||||||
frappe.db.set_value("Employee", employee, "holiday_list", self.holiday_list)
|
frappe.db.set_value("Employee", employee, "holiday_list", self.holiday_list)
|
||||||
|
|
||||||
first_sunday = get_first_sunday(self.holiday_list, for_date=first_day)
|
mark_attendance(employee, attendance_date, "Present")
|
||||||
mark_attendance(employee, first_day, "Present")
|
month_name = get_month_name(attendance_date)
|
||||||
month_name = get_month_name(first_day)
|
|
||||||
|
|
||||||
unmarked_days = get_unmarked_days(employee, month_name)
|
unmarked_days = get_unmarked_days(employee, month_name)
|
||||||
unmarked_days = [getdate(date) for date in unmarked_days]
|
unmarked_days = [getdate(date) for date in unmarked_days]
|
||||||
|
|
||||||
# attendance already marked for the day
|
# attendance already marked for the day
|
||||||
self.assertNotIn(first_day, unmarked_days)
|
self.assertNotIn(attendance_date, unmarked_days)
|
||||||
# attendance unmarked
|
# attendance unmarked
|
||||||
self.assertIn(getdate(add_days(first_day, 1)), unmarked_days)
|
self.assertIn(getdate(add_days(attendance_date, 1)), unmarked_days)
|
||||||
# holiday considered in unmarked days
|
# holiday considered in unmarked days
|
||||||
self.assertIn(first_sunday, unmarked_days)
|
self.assertIn(first_sunday, unmarked_days)
|
||||||
|
|
||||||
def test_unmarked_days_excluding_holidays(self):
|
def test_unmarked_days_excluding_holidays(self):
|
||||||
now = now_datetime()
|
first_sunday = get_first_sunday(
|
||||||
previous_month = now.month - 1
|
self.holiday_list, for_date=get_last_day(add_months(getdate(), -1))
|
||||||
first_day = now.replace(day=1).replace(month=previous_month).date()
|
)
|
||||||
|
attendance_date = add_days(first_sunday, 1)
|
||||||
|
|
||||||
employee = make_employee(
|
employee = make_employee(
|
||||||
"test_unmarked_days@example.com", date_of_joining=add_days(first_day, -1)
|
"test_unmarked_days@example.com", date_of_joining=add_days(attendance_date, -1)
|
||||||
)
|
)
|
||||||
frappe.db.delete("Attendance", {"employee": employee})
|
frappe.db.delete("Attendance", {"employee": employee})
|
||||||
|
|
||||||
frappe.db.set_value("Employee", employee, "holiday_list", self.holiday_list)
|
frappe.db.set_value("Employee", employee, "holiday_list", self.holiday_list)
|
||||||
|
|
||||||
first_sunday = get_first_sunday(self.holiday_list, for_date=first_day)
|
mark_attendance(employee, attendance_date, "Present")
|
||||||
mark_attendance(employee, first_day, "Present")
|
month_name = get_month_name(attendance_date)
|
||||||
month_name = get_month_name(first_day)
|
|
||||||
|
|
||||||
unmarked_days = get_unmarked_days(employee, month_name, exclude_holidays=True)
|
unmarked_days = get_unmarked_days(employee, month_name, exclude_holidays=True)
|
||||||
unmarked_days = [getdate(date) for date in unmarked_days]
|
unmarked_days = [getdate(date) for date in unmarked_days]
|
||||||
|
|
||||||
# attendance already marked for the day
|
# attendance already marked for the day
|
||||||
self.assertNotIn(first_day, unmarked_days)
|
self.assertNotIn(attendance_date, unmarked_days)
|
||||||
# attendance unmarked
|
# attendance unmarked
|
||||||
self.assertIn(getdate(add_days(first_day, 1)), unmarked_days)
|
self.assertIn(getdate(add_days(attendance_date, 1)), unmarked_days)
|
||||||
# holidays not considered in unmarked days
|
# holidays not considered in unmarked days
|
||||||
self.assertNotIn(first_sunday, unmarked_days)
|
self.assertNotIn(first_sunday, unmarked_days)
|
||||||
|
|
||||||
def test_unmarked_days_as_per_joining_and_relieving_dates(self):
|
def test_unmarked_days_as_per_joining_and_relieving_dates(self):
|
||||||
now = now_datetime()
|
first_sunday = get_first_sunday(
|
||||||
previous_month = now.month - 1
|
self.holiday_list, for_date=get_last_day(add_months(getdate(), -1))
|
||||||
first_day = now.replace(day=1).replace(month=previous_month).date()
|
)
|
||||||
|
date = add_days(first_sunday, 1)
|
||||||
|
|
||||||
doj = add_days(first_day, 1)
|
doj = add_days(date, 1)
|
||||||
relieving_date = add_days(first_day, 5)
|
relieving_date = add_days(date, 5)
|
||||||
employee = make_employee(
|
employee = make_employee(
|
||||||
"test_unmarked_days_as_per_doj@example.com", date_of_joining=doj, relieving_date=relieving_date
|
"test_unmarked_days_as_per_doj@example.com", date_of_joining=doj, relieving_date=relieving_date
|
||||||
)
|
)
|
||||||
@@ -99,9 +108,9 @@ class TestAttendance(FrappeTestCase):
|
|||||||
|
|
||||||
frappe.db.set_value("Employee", employee, "holiday_list", self.holiday_list)
|
frappe.db.set_value("Employee", employee, "holiday_list", self.holiday_list)
|
||||||
|
|
||||||
attendance_date = add_days(first_day, 2)
|
attendance_date = add_days(date, 2)
|
||||||
mark_attendance(employee, attendance_date, "Present")
|
mark_attendance(employee, attendance_date, "Present")
|
||||||
month_name = get_month_name(first_day)
|
month_name = get_month_name(attendance_date)
|
||||||
|
|
||||||
unmarked_days = get_unmarked_days(employee, month_name)
|
unmarked_days = get_unmarked_days(employee, month_name)
|
||||||
unmarked_days = [getdate(date) for date in unmarked_days]
|
unmarked_days = [getdate(date) for date in unmarked_days]
|
||||||
|
|||||||
Reference in New Issue
Block a user