From 328a55749d8666028544e098cd280865d946f861 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Fri, 5 Jun 2020 16:46:57 +0530 Subject: [PATCH] fix(HR): Fix half day error when only 1 day is selected (#22122) * fix half day error when only 1 day is selected * adding validation fix for half day on serverside --- erpnext/hr/doctype/leave_application/leave_application.js | 3 +++ erpnext/hr/doctype/leave_application/leave_application.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js index 473aae6f42..15ce468c13 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.js +++ b/erpnext/hr/doctype/leave_application/leave_application.js @@ -38,6 +38,9 @@ frappe.ui.form.on("Leave Application", { }, validate: function(frm) { + if (frm.doc.from_date == frm.doc.to_date && frm.doc.half_day == 1){ + frm.doc.half_day_date = frm.doc.from_date; + } frm.toggle_reqd("half_day_date", frm.doc.half_day == 1); }, diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index f2968bcd88..5eb84d770a 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -33,6 +33,7 @@ class LeaveApplication(Document): self.validate_block_days() self.validate_salary_processed_days() self.validate_attendance() + self.set_half_day_date() if frappe.db.get_value("Leave Type", self.leave_type, 'is_optional_leave'): self.validate_optional_leave() self.validate_applicable_after() @@ -292,6 +293,10 @@ class LeaveApplication(Document): frappe.throw(_("{0} is not in Optional Holiday List").format(formatdate(day)), NotAnOptionalHoliday) day = add_days(day, 1) + def set_half_day_date(self): + if self.from_date == self.to_date and self.half_day == 1: + self.half_day_date = self.from_date + def notify_employee(self): employee = frappe.get_doc("Employee", self.employee) if not employee.user_id: