Erpnext: Scripts in Leave Application not correctly calculating Half Days.

Created on 1 Oct 2019  Â·  2Comments  Â·  Source: frappe/erpnext

Hi,

i have newest version on development branch and noticed in Leave Application Dashboard that scripts calculating Half Day as 1.0, not as 0.5.

My quick solution:
leave_application.py file:

Available Leaves Fix

Actual:

def get_leaves_for_period(employee, leave_type, from_date, to_date):
    leave_entries = get_leave_entries(employee, leave_type, from_date, to_date)
    leave_days = 0

    for leave_entry in leave_entries:
        inclusive_period = leave_entry.from_date >= getdate(from_date) and leave_entry.to_date <= getdate(to_date)

        if  inclusive_period and leave_entry.transaction_type == 'Leave Encashment':
            leave_days += leave_entry.leaves

        elif inclusive_period and leave_entry.transaction_type == 'Leave Allocation' \
            and not skip_expiry_leaves(leave_entry, to_date):
            leave_days += leave_entry.leaves

        else:
            if leave_entry.from_date < getdate(from_date):
                leave_entry.from_date = from_date
            if leave_entry.to_date > getdate(to_date):
                leave_entry.to_date = to_date

            leave_days += get_number_of_leave_days(employee, leave_type,
                leave_entry.from_date, leave_entry.to_date) * -1

…

My fix:

def get_leaves_for_period(employee, leave_type, from_date, to_date):
    leave_entries = get_leave_entries(employee, leave_type, from_date, to_date)
    leave_days = 0

    for leave_entry in leave_entries:
        inclusive_period = leave_entry.from_date >= getdate(from_date) and leave_entry.to_date <= getdate(to_date)

        if  inclusive_period and leave_entry.transaction_type == 'Leave Encashment':
            leave_days += leave_entry.leaves

        elif inclusive_period and leave_entry.transaction_type == 'Leave Allocation' \
            and not skip_expiry_leaves(leave_entry, to_date):
            leave_days += leave_entry.leaves

        elif inclusive_period and leave_entry.transaction_type == 'Leave Application' \
            and not skip_expiry_leaves(leave_entry, to_date):
            leave_days += leave_entry.leaves

        else:
            if leave_entry.from_date < getdate(from_date):
                leave_entry.from_date = from_date
            if leave_entry.to_date > getdate(to_date):
                leave_entry.to_date = to_date

            leave_days += get_number_of_leave_days(employee, leave_type,
                leave_entry.from_date, leave_entry.to_date) * -1

Pending Leaves Fix

Actual:

def get_pending_leaves_for_period(employee, leave_type, from_date, to_date):
    ''' Returns leaves that are pending approval '''
    return frappe.db.get_value("Leave Application",
        filters={
            "employee": employee,
            "leave_type": leave_type,
            "from_date": ("<=", from_date),
            "to_date": (">=", to_date),
            "status": "Open"
        }, fieldname=['SUM(total_leave_days)']) or flt(0)

My fix:

def get_pending_leaves_for_period(employee, leave_type, from_date, to_date):
    ''' Returns leaves that are pending approval '''
    return frappe.db.get_value("Leave Application",
        filters={
            "employee": employee,
            "leave_type": leave_type,
            "from_date": (">=", from_date),
            "to_date": ("<=", to_date),
            "status": "Open"
        }, fieldname=['SUM(total_leave_days)']) or flt(0)
V12 bug human-resources

Most helpful comment

I have added fixes for both the problems over here: #19323 #19411

All 2 comments

I have added fixes for both the problems over here: #19323 #19411

Was this page helpful?
0 / 5 - 0 ratings

Related issues

setsero71 picture setsero71  Â·  3Comments

neilLasrado picture neilLasrado  Â·  4Comments

berniezhao11 picture berniezhao11  Â·  4Comments

vorasmit picture vorasmit  Â·  3Comments

jboilesen picture jboilesen  Â·  3Comments