Leave Policy Assignment

Hi @Everyone

I have a leave management scenario and need guidance on how to handle it.

Requirement:

I need to assign three leave types to an employee:

  • Casual Leave (CL)

  • Sick Leave (SL)

  • Earned Leave (EL)

The rules are as follows:

  • Sick Leave & Casual Leave

    • Total: 3 leaves in 6 months

    • Monthly restriction: 0.5 leave per month

    • Employee should NOT be able to take all 3 SL/CL in a single month

  • Earned Leave

    • Total: 6 leaves in 6 months

    • No monthly restriction

    • Employee can take all 6 EL in a single month, if needed

Scenario 1: Single Leave Policy for 6 Months

I created one Leave Policy with:

  • SL = 3

  • CL = 3

  • EL = 6
    and assigned it for a 6-month leave period.

Issue:
Since the Maximum Leave Allocation Allowed per Leave Period is 3 for SL/CL, the employee is able to apply for all 3 Sick or Casual leaves in a single month, which violates the monthly restriction of 0.5 leave.

Scenario 2: Monthly Leave Policy Assignment

To enforce the monthly restriction, I tried:

  • Creating a 1-month Leave Policy Assignment for Sick & Casual Leave

  • Keeping Earned Leave separate

This approach works for enforcing the 0.5 leave per month restriction.

Problem:

  1. Unable to create 6month Leave Period and Single month leave period as there is a restriction.
  2. Unable to create another Leave Policy Assignment for the same employee when one already exists for that period.
    Overlapping or multiple Leave Policy Assignments for the same period are not allowed.

Can anyone suggest/guide me?

Any suggestions or best practices would be greatly appreciated.
Thanks in advance!

Hiii @avc any suggestions??

hello @Kiranmai_M the fastest way to do that is using a client script by validating the form against the employee leaves type, how many approved CL/SL in the same month, also i version 15 if you mark the CL/SL as an Earned Leave and make the sequence monthly and Allocated Day fist day of the month with rounding 0.25 that should work too

1 Like

@Gharieb Thank you, And i want another one.

need to assign the leave policy for 1 year(annually) but the earned leave should be expired in 6 months, how can i do this?

in this case i would create the period for 6 month because you can’t have 2 active periods and reassign the policy when it ends OR create a Leave Block List for the Leave Types that should expired and block the 6 month

@Gharieb Great, Thank you for your time and support.

Do you have any idea on below one??

I have a leave period defined for one year. When an employee creates a Compensatory Leave Request, a Leave Allocation is automatically created upon submission.

Currently, while creating the leave allocation, the system uses the leave period in which the from and to dates of the compensatory leave request fall (in this case, one year). However, I want these compensatory leaves to expire after 3 months.

How can I achieve this? Do you have any suggestions?

if i did got you point so you want to prevent the employee to claim the compensatory leave if it pass 3-month since you have a leave period for one year you can not use the leave type config to do it, a client script will do the job just validate the Work End Date against the expire date

an option add a custom field to the compensatory leave form custom_expiry_date (read_only)

create a client script for compensatory leave Request :

 frappe.ui.form.on('Compensatory Leave Request', {
	work_end_date: function(frm) {
        // When the user enters the date they worked, calculate 3 months later
        if (frm.doc.work_end_date) {
            // Add 90 days (approx 3 months) to the work date
            let expiry_date = frappe.datetime.add_days(frm.doc.work_end_date, 90);
            
            // Set the expiry date in the document
            frm.set_value('custom_expiry_date', expiry_date);
            
            frappe.msgprint({
                title: __('Expiry Set'),
                indicator: 'blue',
                message: __('This leave will expire on {0} (90 days from work date).', [frappe.datetime.str_to_user(expiry_date)])
            });
        }
    },
    validate: function(frm) {
        // Safety check: Ensure they aren't trying to set an expiry longer than 3 months manually
        if (frm.doc.work_end_date && frm.doc.custom_expiry_date) {
            let max_expiry = frappe.datetime.add_days(frm.doc.work_end_date, 90);
            
            if (frm.doc.expiry_date > max_expiry) {
                frappe.msgprint(__('Expiry date cannot be more than 3 months (90 days) from the work date.'));
                frappe.validated = false;
            }
        }
    }
})

if you have any other questions - pls open new topic!!! hope this is helps : :slightly_smiling_face: