Test case for Attendance Request (#14566)
* Add test case for Attendance Request * Add a message if attendance not submitted * Add test for cancelled document
This commit is contained in:
parent
97124e92fa
commit
b0575265fb
@ -49,6 +49,7 @@ class AttendanceRequest(Document):
|
||||
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 @@ class AttendanceRequest(Document):
|
||||
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
|
||||
|
@ -5,6 +5,34 @@ from __future__ import unicode_literals
|
||||
|
||||
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")
|
Loading…
Reference in New Issue
Block a user