Skip to content

Commit

Permalink
Merge pull request #2415 from frappe/version-15-hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal authored Nov 13, 2024
2 parents cbdeab7 + 9f7d711 commit 9b9eb7d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ def get_allocated_and_expired_leaves(
carry_forwarded_leaves += record.leaves
else:
new_allocation += record.leaves

# carry forwarded leaves also get counted in expired, hence subtracting them
expired_leaves -= carry_forwarded_leaves
return new_allocation, expired_leaves, carry_forwarded_leaves


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,47 @@ def test_employee_status_filter(self):
)
report = execute(filters)
self.assertEqual(len(report[1]), 1)

@set_holiday_list("_Test Emp Balance Holiday List", "_Test Company")
def test_closing_balance_considers_carry_forwarded_leaves(self):
leave_type = create_leave_type(leave_type_name="_Test_CF_leave_expiry", is_carry_forward=1)
# 30 leaves allocated for first half of the year
allocation1 = make_allocation_record(
employee=self.employee_id,
from_date=self.year_start,
to_date=self.mid_year,
leave_type=leave_type.name,
)
# 4 days leave application in the first allocation
first_sunday = get_first_sunday(self.holiday_list, for_date=self.year_start)
leave_application = make_leave_application(
self.employee_id, first_sunday, add_days(first_sunday, 3), leave_type.name
)
leave_application.reload()
# expires 26 leaves
process_expired_allocation()
# carry forward 26 expired leaves + allocate 4 new leaves
allocation2 = make_allocation_record(
employee=self.employee_id,
from_date=add_days(self.mid_year, 1),
to_date=self.year_end,
leaves=4,
carry_forward=True,
leave_type=leave_type.name,
)

filters = frappe._dict(
{
"from_date": self.year_start,
"to_date": self.year_end,
"employee": self.employee_id,
}
)
report = execute(filters)

closing_balance = (
allocation1.new_leaves_allocated
- leave_application.total_leave_days
+ allocation2.new_leaves_allocated
)
self.assertEqual(report[1][0].closing_balance, closing_balance)

0 comments on commit 9b9eb7d

Please sign in to comment.