Hi everyone I’m working on a custom leave policy for a client (KSPACE) using ERPNext v15.27.6 and HRMS v16.0.0-dev. The policy involves two interconnected leave types:
- Half Pay Leave (20 days/year)
- Commuted Leave (10 days/year)
The business rule is:
- If an employee applies for a leave with type “Half Pay” and the number of days is a multiple of 2, then for every 2 Half Pay days, we need to deduct 2 Half Pay + 1 Commuted leave.
- Conversely, if they apply for 1 Commuted Leave, it should deduct 1 Commuted + 2 Half Pay leaves.
- If the number of Half Pay leave days is not a perfect multiple of 2 (like 3), the rule still applies proportionally: deduct 2 Half Pay + 1 Commuted, then the remaining 1 Half Pay alone.
I have written a custom hook (
on_submit
) in my custom app that creates an extra Leave Ledger Entry for the second leave type (e.g., creates a Commuted ledger entry when applying Half Pay).
The issue:
- The Leave Ledger shows the correct entries for both leave types.
- The Employee Leave Balance Report shows the incorrect balance.
- When the employee opens a new Leave Application, the **leave balance shown is also inconsistent, and is different from what I shown in the employee leave balance report.
My question:
What is the correct/best-practice way to deduct leave from two leave types in a single Leave Application, while ensuring:
- The Leave Ledger tracks both deductions,
- The Employee Leave Balance Report shows the correct remaining balances for both leave types,
- The Leave Application form shows accurate balance info when applying for future leaves?
Any guidance or examples from others who’ve done similar “multi-type leave deductions” would be super helpful
Thanks in advance!