From c64825374f25e02fb6a3a64718ac66f558665f06 Mon Sep 17 00:00:00 2001 From: krantheman Date: Tue, 8 Oct 2024 14:18:07 +0530 Subject: [PATCH 1/2] fix(Salary Slip): consider only leaves taken until End Date in Leave Details (cherry picked from commit bd11ed045936280164de8ff25f048f2e980520ee) --- .../doctype/leave_application/leave_application.py | 14 +++++++++----- hrms/payroll/doctype/salary_slip/salary_slip.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hrms/hr/doctype/leave_application/leave_application.py b/hrms/hr/doctype/leave_application/leave_application.py index abce232a08..c8824d9eef 100755 --- a/hrms/hr/doctype/leave_application/leave_application.py +++ b/hrms/hr/doctype/leave_application/leave_application.py @@ -827,20 +827,24 @@ def get_number_of_leave_days( @frappe.whitelist() -def get_leave_details(employee, date): +def get_leave_details(employee, date, for_salary_slip=False): allocation_records = get_leave_allocation_records(employee, date) leave_allocation = {} precision = cint(frappe.db.get_single_value("System Settings", "float_precision", cache=True)) for d in allocation_records: allocation = allocation_records.get(d, frappe._dict()) + to_date = date if for_salary_slip else allocation.to_date remaining_leaves = get_leave_balance_on( - employee, d, date, to_date=allocation.to_date, consider_all_leaves_in_the_allocation_period=True + employee, + d, + date, + to_date=to_date, + consider_all_leaves_in_the_allocation_period=False if for_salary_slip else True, ) - end_date = allocation.to_date - leaves_taken = get_leaves_for_period(employee, d, allocation.from_date, end_date) * -1 - leaves_pending = get_leaves_pending_approval_for_period(employee, d, allocation.from_date, end_date) + leaves_taken = get_leaves_for_period(employee, d, allocation.from_date, to_date) * -1 + leaves_pending = get_leaves_pending_approval_for_period(employee, d, allocation.from_date, to_date) expired_leaves = allocation.total_leaves_allocated - (remaining_leaves + leaves_taken) leave_allocation[d] = { diff --git a/hrms/payroll/doctype/salary_slip/salary_slip.py b/hrms/payroll/doctype/salary_slip/salary_slip.py index d4b5bf3cac..5001308d5f 100644 --- a/hrms/payroll/doctype/salary_slip/salary_slip.py +++ b/hrms/payroll/doctype/salary_slip/salary_slip.py @@ -2103,7 +2103,7 @@ def add_leave_balances(self): if frappe.db.get_single_value("Payroll Settings", "show_leave_balances_in_salary_slip"): from hrms.hr.doctype.leave_application.leave_application import get_leave_details - leave_details = get_leave_details(self.employee, self.end_date) + leave_details = get_leave_details(self.employee, self.end_date, True) for leave_type, leave_values in leave_details["leave_allocation"].items(): self.append( From 395444e25711aecb8650bc64f94fbada1890f451 Mon Sep 17 00:00:00 2001 From: krantheman Date: Tue, 8 Oct 2024 17:44:40 +0530 Subject: [PATCH 2/2] test(Salary Slip): leave details (cherry picked from commit a34b211a3873dc896c3e6fbb2c69d6590b0a6f5f) --- .../doctype/salary_slip/test_salary_slip.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hrms/payroll/doctype/salary_slip/test_salary_slip.py b/hrms/payroll/doctype/salary_slip/test_salary_slip.py index 32d7b4aa6d..47c37f8021 100644 --- a/hrms/payroll/doctype/salary_slip/test_salary_slip.py +++ b/hrms/payroll/doctype/salary_slip/test_salary_slip.py @@ -54,6 +54,35 @@ def tearDown(self): frappe.db.set_value("Payroll Settings", None, "include_holidays_in_total_working_days", 0) frappe.set_user("Administrator") + @change_settings("Payroll Settings", {"show_leave_balances_in_salary_slip": True}) + def test_leave_details(self): + from hrms.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure + + emp_id = make_employee("test_leave_details@salary.com") + + first_sunday = get_first_sunday() + alloc = create_leave_allocation( + employee=emp_id, + from_date=first_sunday, + to_date=add_months(first_sunday, 10), + new_leaves_allocated=10, + leave_type="_Test Leave Type", + ) + alloc.save() + alloc.submit() + + make_leave_application(emp_id, first_sunday, add_days(first_sunday, 3), "_Test Leave Type") + next_month = add_months(nowdate(), 1) + make_leave_application(emp_id, next_month, add_days(next_month, 3), "_Test Leave Type") + ss = make_employee_salary_slip(emp_id, "Monthly") + + leave_detail = ss.leave_details[0] + self.assertEqual(leave_detail.leave_type, "_Test Leave Type") + self.assertEqual(leave_detail.total_allocated_leaves, 10) + self.assertEqual(leave_detail.expired_leaves, 0) + self.assertEqual(leave_detail.used_leaves, 4) + self.assertEqual(leave_detail.available_leaves, 6) + def test_employee_status_inactive(self): from hrms.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure