From f16d21d9fb9b99a81ef87f7f0b495b9a325bb3e1 Mon Sep 17 00:00:00 2001 From: wreckage0907 Date: Fri, 26 Jun 2026 23:00:03 +0530 Subject: [PATCH 1/3] fix: full day + half day leave on today validation --- hrms/hr/doctype/leave_application/leave_application.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hrms/hr/doctype/leave_application/leave_application.py b/hrms/hr/doctype/leave_application/leave_application.py index c1ec44369a..92bece1cd3 100755 --- a/hrms/hr/doctype/leave_application/leave_application.py +++ b/hrms/hr/doctype/leave_application/leave_application.py @@ -490,7 +490,7 @@ def validate_leave_overlap(self): for d in frappe.db.sql( """ select - name, leave_type, posting_date, from_date, to_date, total_leave_days, half_day_date + name, leave_type, posting_date, from_date, to_date, total_leave_days, half_day, half_day_date from `tabLeave Application` where employee = %(employee)s and docstatus < 2 and status in ('Open', 'Approved') and to_date >= %(from_date)s and from_date <= %(to_date)s @@ -505,6 +505,7 @@ def validate_leave_overlap(self): ): if ( cint(self.half_day) == 1 + and cint(d.half_day) == 1 and getdate(self.half_day_date) == getdate(d.half_day_date) and ( flt(self.total_leave_days) == 0.5 From 67a8cba641d24267eb8f4816008bd1fa1d0ba83c Mon Sep 17 00:00:00 2001 From: wreckage0907 Date: Thu, 2 Jul 2026 14:39:20 +0530 Subject: [PATCH 2/3] test: add overlap test for half day leave on today --- .../test_leave_application.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hrms/hr/doctype/leave_application/test_leave_application.py b/hrms/hr/doctype/leave_application/test_leave_application.py index a2e3e5a64e..3be2027832 100644 --- a/hrms/hr/doctype/leave_application/test_leave_application.py +++ b/hrms/hr/doctype/leave_application/test_leave_application.py @@ -483,6 +483,29 @@ def test_overlap_with_half_day_3(self): application.half_day_date = "2013-01-05" application.insert() + def test_overlap_with_half_day_on_today(self): + self._clear_roles() + + from frappe.utils.user import add_role + + add_role("test@example.com", "Employee") + frappe.set_user("test@example.com") + + # full day leave on today (half_day_date stays NULL) + application = self.get_application(self.leave_application) + application.from_date = application.to_date = nowdate() + application.insert() + + # half day leave on the same day must overlap regardless of the date: + # a NULL half_day_date on the existing full day leave coerces to today via + # getdate(None), so the date must not be the only thing distinguishing them + application = self.get_application(self.leave_application) + application.from_date = application.to_date = nowdate() + application.half_day = 1 + application.half_day_date = nowdate() + + self.assertRaises(OverlapError, application.insert) + @assign_holiday_list("Salary Slip Test Holiday List", "_Test Company") def test_optional_leave(self): leave_period = get_leave_period(current=True) From ca14c3b9f0c9148d29298b37b004184fb1e6726e Mon Sep 17 00:00:00 2001 From: wreckage0907 Date: Thu, 2 Jul 2026 15:20:00 +0530 Subject: [PATCH 3/3] test: make leave allocation before inserting leave application --- .../leave_application/test_leave_application.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hrms/hr/doctype/leave_application/test_leave_application.py b/hrms/hr/doctype/leave_application/test_leave_application.py index 3be2027832..25884341a5 100644 --- a/hrms/hr/doctype/leave_application/test_leave_application.py +++ b/hrms/hr/doctype/leave_application/test_leave_application.py @@ -491,6 +491,16 @@ def test_overlap_with_half_day_on_today(self): add_role("test@example.com", "Employee") frappe.set_user("test@example.com") + # allocate leave covering today so the applications aren't rejected for + # being outside the allocation period + date = getdate() + make_allocation_record( + employee=get_employee().name, + leave_type="_Test Leave Type", + from_date=get_year_start(date), + to_date=get_year_ending(date), + ) + # full day leave on today (half_day_date stays NULL) application = self.get_application(self.leave_application) application.from_date = application.to_date = nowdate()