Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hrms/hr/doctype/leave_application/leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions hrms/hr/doctype/leave_application/test_leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading