How to Deduct Two Leave Types from One Leave Application

Hi everyone :wave: 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.

:hammer_and_wrench: 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).

:bar_chart: 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.

:point_right: My question:
What is the correct/best-practice way to deduct leave from two leave types in a single Leave Application, while ensuring:

  1. The Leave Ledger tracks both deductions,
  2. The Employee Leave Balance Report shows the correct remaining balances for both leave types,
  3. 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 :pray:

Thanks in advance!