From 964deaca96e7a4ea5fc8f2eea03297a70720b5f6 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Mon, 13 May 2019 19:19:39 +0530 Subject: [PATCH] test: creation of ledger entries on application submit --- .../test_leave_application.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index d3dcca1da0..2581c2a659 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -457,6 +457,28 @@ class TestLeaveApplication(unittest.TestCase): leave_application.submit() self.assertEqual(leave_application.docstatus, 1) + def test_creation_of_leave_ledger_entry_on_submit(self): + + leave_application = frappe.get_doc(dict( + doctype = 'Leave Application', + employee = employee.name, + leave_type = leave_type_1.name, + from_date = nowdate(), + to_date = add_days(nowdate(), 4), + company = "_Test Company", + docstatus = 1, + status = "Approved" + )).submit() + leave_ledger_entry = frappe.get_all('Leave Ledger Entry', fields='*', filters=dict(transaction_name=leave_application.name)) + + self.assertEquals(leave_ledger_entry[0].employee, leave_application.employee) + self.assertEquals(leave_ledger_entry[0].leave_type, leave_application.leave_type) + self.assertEquals(leave_ledger_entry[0].leaves, leave_application.new_leaves_allocated) + + # check if leave ledger entry is deleted on cancellation + leave_application.cancel() + self.assertFalse(frappe.db.exists("Leave Ledger Entry", {'transaction_name':leave_application.name})) + def make_allocation_record(employee=None, leave_type=None): frappe.db.sql("delete from `tabLeave Allocation`") @@ -513,4 +535,4 @@ def allocate_leaves(employee, leave_period, leave_type, new_leaves_allocated, el "docstatus": 1 }).insert() - allocate_leave.submit() + allocate_leave.submit() \ No newline at end of file