Test case for Attendance Request (#14566)
* Add test case for Attendance Request
* Add a message if attendance not submitted
* Add test for cancelled document
diff --git a/erpnext/hr/doctype/attendance_request/attendance_request.py b/erpnext/hr/doctype/attendance_request/attendance_request.py
index 4cab11f..a4598a7 100644
--- a/erpnext/hr/doctype/attendance_request/attendance_request.py
+++ b/erpnext/hr/doctype/attendance_request/attendance_request.py
@@ -49,6 +49,7 @@
def validate_if_attendance_not_applicable(self, attendance_date):
# Check if attendance_date is a Holiday
if is_holiday(self.employee, attendance_date):
+ frappe.msgprint(_("Attendance not submitted for {0} as it is a Holiday.").format(attendance_date), alert=1)
return True
# Check if employee on Leave
@@ -56,6 +57,7 @@
where employee = %s and %s between from_date and to_date
and docstatus = 1""", (self.employee, attendance_date), as_dict=True)
if leave_record:
+ frappe.msgprint(_("Attendance not submitted for {0} as {1} on leave.").format(attendance_date, self.employee), alert=1)
return True
return False
diff --git a/erpnext/hr/doctype/attendance_request/test_attendance_request.py b/erpnext/hr/doctype/attendance_request/test_attendance_request.py
index d737699..a2c39d9 100644
--- a/erpnext/hr/doctype/attendance_request/test_attendance_request.py
+++ b/erpnext/hr/doctype/attendance_request/test_attendance_request.py
@@ -5,6 +5,34 @@
import frappe
import unittest
+from frappe.utils import nowdate
+from datetime import date
class TestAttendanceRequest(unittest.TestCase):
- pass
+ def setUp(self):
+ for doctype in ["Attendance Request", "Attendance"]:
+ frappe.db.sql("delete from `tab{doctype}`".format(doctype=doctype))
+
+ def test_attendance_request(self):
+ today = nowdate()
+ employee = get_employee()
+ attendance_request = frappe.new_doc("Attendance Request")
+ attendance_request.employee = employee.name
+ attendance_request.from_date = date(date.today().year, 1, 1)
+ attendance_request.to_date = date(date.today().year, 1, 2)
+ attendance_request.reason = "Work From Home"
+ attendance_request.company = "_Test Company"
+ attendance_request.insert()
+ attendance_request.submit()
+ attendance = frappe.get_doc('Attendance', {
+ 'employee': employee.name,
+ 'attendance_date': date(date.today().year, 1, 1),
+ 'docstatus': 1
+ })
+ self.assertEqual(attendance.status, 'Present')
+ attendance_request.cancel()
+ attendance.reload()
+ self.assertEqual(attendance.docstatus, 2)
+
+def get_employee():
+ return frappe.get_doc("Employee", "_T-Employee-00001")
\ No newline at end of file