From b0575265fbdeeb54a4e684de4f464b01b34eadfc Mon Sep 17 00:00:00 2001 From: Shreya Shah Date: Tue, 19 Jun 2018 10:47:40 +0530 Subject: [PATCH] Test case for Attendance Request (#14566) * Add test case for Attendance Request * Add a message if attendance not submitted * Add test for cancelled document --- .../attendance_request/attendance_request.py | 2 ++ .../test_attendance_request.py | 30 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/attendance_request/attendance_request.py b/erpnext/hr/doctype/attendance_request/attendance_request.py index 4cab11fef5..a4598a798e 100644 --- a/erpnext/hr/doctype/attendance_request/attendance_request.py +++ b/erpnext/hr/doctype/attendance_request/attendance_request.py @@ -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 diff --git a/erpnext/hr/doctype/attendance_request/test_attendance_request.py b/erpnext/hr/doctype/attendance_request/test_attendance_request.py index d737699f6b..a2c39d9a71 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 @@ 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") \ No newline at end of file