fix: convert dates to datetime before comparing in leave days calculation and fix half day edge case (#30538)
This commit is contained in:
parent
257623509d
commit
65763275ae
@ -735,9 +735,9 @@ def get_number_of_leave_days(
|
||||
(Based on the include_holiday setting in Leave Type)"""
|
||||
number_of_days = 0
|
||||
if cint(half_day) == 1:
|
||||
if from_date == to_date:
|
||||
if getdate(from_date) == getdate(to_date):
|
||||
number_of_days = 0.5
|
||||
elif half_day_date and half_day_date <= to_date:
|
||||
elif half_day_date and getdate(from_date) <= getdate(half_day_date) <= getdate(to_date):
|
||||
number_of_days = date_diff(to_date, from_date) + 0.5
|
||||
else:
|
||||
number_of_days = date_diff(to_date, from_date) + 1
|
||||
|
@ -205,7 +205,12 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
# creates separate leave ledger entries
|
||||
frappe.delete_doc_if_exists("Leave Type", "Test Leave Validation", force=1)
|
||||
leave_type = frappe.get_doc(
|
||||
dict(leave_type_name="Test Leave Validation", doctype="Leave Type", allow_negative=True)
|
||||
dict(
|
||||
leave_type_name="Test Leave Validation",
|
||||
doctype="Leave Type",
|
||||
allow_negative=True,
|
||||
include_holiday=True,
|
||||
)
|
||||
).insert()
|
||||
|
||||
employee = get_employee()
|
||||
@ -217,8 +222,14 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
# application across allocations
|
||||
|
||||
# CASE 1: from date has no allocation, to date has an allocation / both dates have allocation
|
||||
start_date = add_days(year_start, -10)
|
||||
application = make_leave_application(
|
||||
employee.name, add_days(year_start, -10), add_days(year_start, 3), leave_type.name
|
||||
employee.name,
|
||||
start_date,
|
||||
add_days(year_start, 3),
|
||||
leave_type.name,
|
||||
half_day=1,
|
||||
half_day_date=start_date,
|
||||
)
|
||||
|
||||
# 2 separate leave ledger entries
|
||||
@ -828,6 +839,7 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
leave_type_name="_Test_CF_leave_expiry",
|
||||
is_carry_forward=1,
|
||||
expire_carry_forwarded_leaves_after_days=90,
|
||||
include_holiday=True,
|
||||
)
|
||||
leave_type.submit()
|
||||
|
||||
@ -840,6 +852,8 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
leave_type=leave_type.name,
|
||||
from_date=add_days(nowdate(), -3),
|
||||
to_date=add_days(nowdate(), 7),
|
||||
half_day=1,
|
||||
half_day_date=add_days(nowdate(), -3),
|
||||
description="_Test Reason",
|
||||
company="_Test Company",
|
||||
docstatus=1,
|
||||
@ -855,7 +869,7 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
self.assertEqual(len(leave_ledger_entry), 2)
|
||||
self.assertEqual(leave_ledger_entry[0].employee, leave_application.employee)
|
||||
self.assertEqual(leave_ledger_entry[0].leave_type, leave_application.leave_type)
|
||||
self.assertEqual(leave_ledger_entry[0].leaves, -9)
|
||||
self.assertEqual(leave_ledger_entry[0].leaves, -8.5)
|
||||
self.assertEqual(leave_ledger_entry[1].leaves, -2)
|
||||
|
||||
def test_leave_application_creation_after_expiry(self):
|
||||
|
@ -1290,7 +1290,16 @@ def create_additional_salary(employee, payroll_period, amount):
|
||||
return salary_date
|
||||
|
||||
|
||||
def make_leave_application(employee, from_date, to_date, leave_type, company=None, submit=True):
|
||||
def make_leave_application(
|
||||
employee,
|
||||
from_date,
|
||||
to_date,
|
||||
leave_type,
|
||||
company=None,
|
||||
half_day=False,
|
||||
half_day_date=None,
|
||||
submit=True,
|
||||
):
|
||||
leave_application = frappe.get_doc(
|
||||
dict(
|
||||
doctype="Leave Application",
|
||||
@ -1298,6 +1307,8 @@ def make_leave_application(employee, from_date, to_date, leave_type, company=Non
|
||||
leave_type=leave_type,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
half_day=half_day,
|
||||
half_day_date=half_day_date,
|
||||
company=company or erpnext.get_default_company() or "_Test Company",
|
||||
status="Approved",
|
||||
leave_approver="test@example.com",
|
||||
|
Loading…
x
Reference in New Issue
Block a user