Skip to content

Commit

Permalink
Merge pull request #2264 from frappe/mergify/bp/version-14-hotfix/pr-…
Browse files Browse the repository at this point in the history
…2260

fix(Salary Slip): consider only leaves taken until End Date in Leave Details (backport #2260)
  • Loading branch information
krantheman authored Oct 8, 2024
2 parents 1842439 + 395444e commit 498373d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
14 changes: 9 additions & 5 deletions hrms/hr/doctype/leave_application/leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
2 changes: 1 addition & 1 deletion hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
29 changes: 29 additions & 0 deletions hrms/payroll/doctype/salary_slip/test_salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]")

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

Expand Down

0 comments on commit 498373d

Please sign in to comment.