From 676094370433bf98a37a9436b000853b1c381fa2 Mon Sep 17 00:00:00 2001 From: krantheman Date: Wed, 25 Sep 2024 16:33:16 +0530 Subject: [PATCH] test: allocate leaves manually --- .../leave_allocation/test_earned_leaves.py | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/hrms/hr/doctype/leave_allocation/test_earned_leaves.py b/hrms/hr/doctype/leave_allocation/test_earned_leaves.py index 0dfdc01818..9f17827f81 100644 --- a/hrms/hr/doctype/leave_allocation/test_earned_leaves.py +++ b/hrms/hr/doctype/leave_allocation/test_earned_leaves.py @@ -3,8 +3,6 @@ from frappe.utils import ( add_days, add_months, - date_diff, - flt, get_first_day, get_last_day, get_year_ending, @@ -477,6 +475,32 @@ def test_get_earned_leave_details_for_dashboard(self): } self.assertEqual(leave_allocation, expected) + def test_allocate_leaves_manually(self): + frappe.flags.current_date = get_year_start(getdate()) + lpas = make_policy_assignment( + self.employee, + allocate_on_day="First Day", + start_date=frappe.flags.current_date, + ) + + leave_allocation = frappe.get_last_doc( + "Leave Allocation", filters={"leave_policy_assignment": lpas[0]} + ) + leave_allocation.allocate_leaves_manually(1) + leave_allocation.allocate_leaves_manually(1) + leave_allocation.allocate_leaves_manually(1) + leave_allocation.allocate_leaves_manually(1) + leave_allocation.allocate_leaves_manually(1) + self.assertEqual( + get_leave_balance_on(self.employee.name, self.leave_type, frappe.flags.current_date), 6 + ) + + leave_allocation.allocate_leaves_manually(6) + self.assertEqual( + get_leave_balance_on(self.employee.name, self.leave_type, frappe.flags.current_date), 12 + ) + self.assertRaises(frappe.ValidationError, leave_allocation.allocate_leaves_manually, 1) + def tearDown(self): frappe.db.set_value("Employee", self.employee.name, "date_of_joining", self.original_doj) frappe.db.set_value("Leave Type", self.leave_type, "max_leaves_allowed", 0)