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 diff --git a/hrms/hr/doctype/leave_application/test_leave_application.py b/hrms/hr/doctype/leave_application/test_leave_application.py index a2e3e5a64e..25884341a5 100644 --- a/hrms/hr/doctype/leave_application/test_leave_application.py +++ b/hrms/hr/doctype/leave_application/test_leave_application.py @@ -483,6 +483,39 @@ 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") + + # 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() + 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)