Automagically expire forwarded leaves after three leave periods

Hello friends,
I have been trying to create a leave type with carry forward selected. I wanted to make sure that any forwarded leaves from the back three leave periods expire and are not to be added to available leaves. I have prepared the leave period with one year (Jan to Dec).

Tried to use Expire Carry Forwarded Leaves (Days) but it is not clear how it works and is not included in the documentation.
Can someone please suggest me a better solution to achieve this?

Since I haven’t received any response on this, I just limited the maximum forwarded leaves so that an employee can not get any excess leaves, which should expire after a certain leave period. :slightly_smiling_face:

Anyone? I am still searching for an answer, please, if anyone has a suggestion, I would really appreciate it.

This is the scenario

Let’s say I have 12 leaves in 22-23 leave period
30 leaves in 23-24 leave period
32 leaves in 24-25 leave period
21 leaves in 25-26 leave period (Active)
Therefore, I want to expire 12 days, which are carried forward from the 22-23 leave period

Anyone please?

Proposed Solution: Leveraging “Maximum Carry Forward” in Frappe HR

Concept

Instead of using complex scripts to track the age of each leave day, this solution uses the built-in Maximum Carry Forward limit as a “ceiling.” By setting this ceiling to the sum of the allowed leave periods (e.g., 3 years), the system will automatically truncate any excess days during the new allocation.

How to Implement

  1. Navigate to Leave Type (e.g., Annual Leave).
  2. Ensure Is Carry Forward is checked.
  3. Set Maximum Carry Forward Leaves to the total sum of 3 years of entitlement.

Example Calculation:

  • Year 1 (22–23): 12 days
  • Year 2 (23–24): 30 days
  • Year 3 (24–25): 32 days
  • Total Capacity: days.
  • Action: Set Maximum Carry Forward Leaves = 74.

:white_check_mark: Pros (Why this works)

  • No Code Required: Uses standard Frappe features, making it easy to maintain and upgrade.
  • Automatic Truncation: During the next Leave Allocation, the system will automatically discard any balance that exceeds the 74-day limit.
  • Liability Control: Effectively limits the company’s financial liability regarding unpaid leave encashment.

:warning: Cons & Limitations (The “Expiry” Logic Gap)

  • Quantity vs. Age: This method tracks the total amount, not the age of the leaves. If a employee uses their leaves regularly, their total balance might always stay below 74. In this case, the “old” days from 2022 are never technically “expired” because the ceiling was never hit.
  • FIFO Issues: Frappe does not strictly follow FIFO (First-In-First-Out) for leave expiry. If an employee takes 10 days today, the system subtracts them from the total pool, but it doesn’t “know” it should have subtracted them from the 2022 balance specifically.
  • Manual Updates: If a employee’s annual entitlement changes (e.g., due to a promotion), you must manually update the Maximum Carry Forward value to reflect the new 3-year total.

Conclusion

This is a highly practical workaround for companies that want an automated way to prevent massive leave hoarding. However, it is a “capacity limit” rather than a true “expiration date” policy.


Thanks @Sharif101, although it seems the answer is from AI, I appreciate your time. But finally I just implemented it using server script and it is working for me.

Thank you.

1 Like