Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: earned leaves not allocated if assignment is created on month-end based on Leave Period #29650

Merged

Conversation

ruchamahabal
Copy link
Member

@ruchamahabal ruchamahabal commented Feb 5, 2022

Background

  1. On the creation of a Leave Policy Assignment for Earned Leaves, allocation of leaves happens in 2 stages:
    • If this assignment is done in the latter months of the leave period, it allocates leaves for past months.
    • then, a daily background job runs for allocating "earned" leaves at the end of every month (in case of monthly frequency)
  2. For eg: the leave period starts from Jan 2022 and you create an assignment in Feb 2022 then it will allocate leave for Jan and then allocate leaves for Feb onwards during month-end as per your frequency set in the leave type

Problem

  1. If you create an assignment on month-end, say 31st Jan 2022, and the policy period starts from 1st Jan 2022, then 1 leave should be allocated since it is the last day of the month.
  2. But this does not happen because as per the current logic, the month has not "passed".
  3. Also, the daily background job would run at 12:00 am on 31st Jan 2022, but if you create an assignment after it, then the job is already over and it will next run on 1st Feb 2022, but this is not the last day of the month, so leave is never allocated for Jan.
Steps to Replicate
  • Leave Type configuration

    image

  • Leave Policy:

    image

  • Leave Policy Assignment created for Jan 2022-Dec 2022 on 31st Jan 2022

    image

  • 0 Total Leaves Allocated in Leave Allocation although Jan has passed (it is 31st)

    image

Fix

  1. If the assignment is created on the last day of the month within the leave period, consider it in "past months" because the employee should already "earn" this leave.
  2. Add a check in the background job allocation to determine if the leave is not already allocated, to avoid duplication.
  3. Add tests for both cases.

1 Leave allocated for Jan on policy assignment creation. Check Total Leaves Allocated

image

  • Handle carry-forwarded leaves while checking if leaves are already allocated

@ruchamahabal ruchamahabal marked this pull request as draft February 6, 2022 15:37
@ruchamahabal ruchamahabal force-pushed the fix-earned-leaves-allocation branch from 12307d1 to 90bbe24 Compare February 8, 2022 09:01
@ruchamahabal ruchamahabal force-pushed the fix-earned-leaves-allocation branch from 90bbe24 to bd1555b Compare February 8, 2022 09:06
@ruchamahabal ruchamahabal marked this pull request as ready for review February 8, 2022 09:11
@codecov
Copy link

codecov bot commented Feb 8, 2022

Codecov Report

Merging #29650 (b71283a) into develop (bb105a3) will increase coverage by 0.20%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop   #29650      +/-   ##
===========================================
+ Coverage    58.88%   59.09%   +0.20%     
===========================================
  Files         1112     1112              
  Lines        69467    69488      +21     
===========================================
+ Hits         40907    41061     +154     
+ Misses       28560    28427     -133     
Impacted Files Coverage Δ
...leave_policy_assignment/leave_policy_assignment.py 87.71% <100.00%> (+1.87%) ⬆️
erpnext/hr/utils.py 76.40% <100.00%> (+1.20%) ⬆️
...rpnext/stock/report/stock_balance/stock_balance.py 79.16% <0.00%> (-0.60%) ⬇️
erpnext/selling/doctype/quotation/quotation.py 49.18% <0.00%> (-0.55%) ⬇️
erpnext/stock/doctype/serial_no/serial_no.py 80.97% <0.00%> (-0.26%) ⬇️
erpnext/stock/doctype/item/item.py 83.04% <0.00%> (-0.18%) ⬇️
erpnext/regional/india/e_invoice/utils.py 42.79% <0.00%> (ø)
...stock/doctype/purchase_receipt/purchase_receipt.py 91.34% <0.00%> (+0.25%) ⬆️
erpnext/projects/doctype/project/project.py 54.89% <0.00%> (+0.34%) ⬆️
erpnext/accounts/report/financial_statements.py 35.63% <0.00%> (+0.38%) ⬆️
... and 24 more

@ruchamahabal ruchamahabal changed the title fix: earned leaves not allocated if assignment is created on month-end fix: earned leaves not allocated if assignment is created on month-end based on Leave Policy Feb 8, 2022
@ruchamahabal ruchamahabal merged commit bdf38a3 into frappe:develop Feb 8, 2022
@ruchamahabal ruchamahabal deleted the fix-earned-leaves-allocation branch February 8, 2022 10:17
@ruchamahabal
Copy link
Member Author

@Mergifyio backport version-13-hotfix

@mergify
Copy link
Contributor

mergify bot commented Feb 8, 2022

backport version-13-hotfix

✅ Backports have been created

@ruchamahabal ruchamahabal changed the title fix: earned leaves not allocated if assignment is created on month-end based on Leave Policy fix: earned leaves not allocated if assignment is created on month-end based on Leave Period Feb 11, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant