Skip to content

Commit

Permalink
Issue 560 refactor employee leave balance (#787)
Browse files Browse the repository at this point in the history
* refactor: Employee Leave Balance Report

- incorrect opening balance on boundary allocation dates

- carry forwarded leaves accounted in leaves allocated column, should be part of opening balance

- leaves allocated column also adds expired leave allocations causing negative balances, should only consider non-expiry records

(cherry picked from commit 538b64b)

* fix: expired leaves not calculated properly because of newly created expiry ledger entries

(cherry picked from commit 1ea749c)

* refactor: Leaves Taken calculation

- fix issue where Leaves Taken also adds leaves expiring on boundary date as leaves taken, causing ambiguity

- remove unnecessary `skip_expiry_leaves` function

- `get_allocation_expiry` considering cancelled entries too

(cherry picked from commit 26b40e7)

* refactor: balance in Balance Summary report near allocation expiry date

- Leave Balance shows minimum leaves remaining after comparing with remaining days for allocation expiry causing ambiguity

- refactor remaining leaves calculation to return both, actual leave balance and balance for consumption

- show actual balance in leave application, use balance for consumption only in validations

(cherry picked from commit 55ac851)

* fix: sort imports, sider issues

(cherry picked from commit b5c686a)

* fix: show actual balance instead of consumption balance in opening balance

- not changing opening balance based on remaining days

(cherry picked from commit dbfa463)

* test: employee leave balance report

- fix expired leaves calculation when filters span across 2 different allocation periods

(cherry picked from commit c050ce4)

* chore: remove unused imports, sort imports, fix sider

(cherry picked from commit c7d5949)

* test: Employee Leave Balance Summary

(cherry picked from commit 88141d6)

* fix: leave application dashboard

- total leaves allocated considering cancelled leaves

- optional plural for leave category labels

- show dashboard only once from date is set, else it fetches all allocations till date and generates incorrect balance

- change pending leaves to 'Leaves Pending Approval' for better context

- update labels in Salary Slip Leave Details table

(cherry picked from commit 942511c)

* fix: earned leave policy assignment test

(cherry picked from commit aaa1ae9)

* test: fix test `test_leave_balance_near_allocaton_expiry`

(cherry picked from commit a58dfec)

* test: get leave details for leave application dashboard

(cherry picked from commit 3f3b176)

* fix: add type hints for employee leave balance report

(cherry picked from commit 430bf00)

* feat: split ledger entries for applications created across allocations

- fix: ledger entry for expiring cf leaves not considering holidays

(cherry picked from commit c0f1e26)

* fix: clearer validation/warning messages for insufficient balance in leave application

(cherry picked from commit a504ffc)

* test: leave application validations

(cherry picked from commit 6755d6e)

* fix: boundary determination for separate ledger entries

(cherry picked from commit 7023915)

* test: separate leave ledger entries for leave applications across allocations

(cherry picked from commit 97b7b50)

* chore: linter issue

(cherry picked from commit 921d6b2)

---------

Co-authored-by: Rucha Mahabal <[email protected]>
  • Loading branch information
fproldan and ruchamahabal authored Aug 29, 2023
1 parent 4574039 commit 9ed1964
Show file tree
Hide file tree
Showing 14 changed files with 1,093 additions and 180 deletions.
22 changes: 22 additions & 0 deletions erpnext/hr/doctype/holiday_list/test_holiday_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import unicode_literals

import unittest
from contextlib import contextmanager
from datetime import timedelta

import frappe
Expand Down Expand Up @@ -31,3 +32,24 @@ def make_holiday_list(name, from_date=getdate()-timedelta(days=10), to_date=getd
"holidays" : holiday_dates
}).insert()
return doc


@contextmanager
def set_holiday_list(holiday_list, company_name):
"""
Context manager for setting holiday list in tests
"""
try:
company = frappe.get_doc('Company', company_name)
previous_holiday_list = company.default_holiday_list

company.default_holiday_list = holiday_list
company.save()

yield

finally:
# restore holiday list setup
company = frappe.get_doc('Company', company_name)
company.default_holiday_list = previous_holiday_list
company.save()
3 changes: 2 additions & 1 deletion erpnext/hr/doctype/leave_application/leave_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ frappe.ui.form.on("Leave Application", {
make_dashboard: function(frm) {
var leave_details;
let lwps;
if (frm.doc.employee) {
if (frm.doc.employee && frm.doc.from_date) {
frappe.call({
method: "erpnext.hr.doctype.leave_application.leave_application.get_leave_details",
async: false,
Expand Down Expand Up @@ -149,6 +149,7 @@ frappe.ui.form.on("Leave Application", {
},

to_date: function(frm) {
frm.trigger("make_dashboard");
frm.trigger("half_day_datepicker");
frm.trigger("calculate_total_days");
},
Expand Down
Loading

0 comments on commit 9ed1964

Please sign in to comment.