Leave Ledger Entry via Server Script not affecting Leave Balance

Friends,

I am trying to implement flexible weekly holiday.
Let me explain what I need:

  1. When an employee Present on his weekly holiday, he will get compensatory leave
  2. The leave will be usable for that specific month.

First I tried:
A server script is triggered when a “Attendance” document is “Submitted” with a status of “Present”. The script will check if that day is included in the holiday list, if so, a “Compensatory Leave Application” is submitted.
In this scenario, I didn’t find a way to let the leaves expire at the end of the month. I’ve also tried using the “Leave Allocation” document, but that doesn’t support creating multiple documents within a date range.

Second I tried:
Instead of creating a “Compensatory Leave Request”, I tried to create a “Leave Ledger Entry” with a range of validity date, but creating a ledger entry doesn’t seem to affect the employee’s leave balance.

Server Script:

try :
    if doc.status == 'Present' :
    
        holiday_list = frappe.db.get_value("Employee", doc.employee, ["holiday_list"])
        if not holiday_list:
        	holiday_list = frappe.get_cached_value("Company", doc.company, "default_holiday_list")

        filters = {"parent": holiday_list, "holiday_date": ("between", [doc.attendance_date, doc.attendance_date])}
        holidays = frappe.get_all("Holiday", fields=["description", "holiday_date"], filters=filters)
#        holidays = [cstr(h.holiday_date) for h in holidays]

        if len(holidays) > 0 :
            newDoc = frappe.new_doc('Leave Ledger Entry')
            newDoc.owner = doc.owner
            newDoc.employee = doc.employee
            newDoc.leave_type = 'Weekend Adjustment'
            newDoc.from_date =  frappe.utils.get_first_day(doc.attendance_date)
            newDoc.to_date = frappe.utils.get_last_day(frappe.utils.add_to_date(doc.attendance_date,months=1))
            newDoc.holiday_list = holiday_list
            newDoc.company = doc.company
            newDoc.leaves = 1
            newDoc.insert()
            newDoc.submit()
        
except Exception:
    pass

I also planned to automatically adjust absences with compensatory leave while creating payslips.

I appreciate your help