Leave Application - validate applicable after for leave type
This commit is contained in:
parent
62a93533fc
commit
3153734e7e
@ -34,6 +34,7 @@ class LeaveApplication(Document):
|
||||
self.validate_attendance()
|
||||
if frappe.db.get_value("Leave Type", self.leave_type, 'is_optional_leave'):
|
||||
self.validate_optional_leave()
|
||||
self.validate_applicable_after()
|
||||
|
||||
def on_update(self):
|
||||
if self.status == "Open" and self.docstatus < 1:
|
||||
@ -55,6 +56,21 @@ class LeaveApplication(Document):
|
||||
# notify leave applier about cancellation
|
||||
self.notify_employee()
|
||||
|
||||
def validate_applicable_after(self):
|
||||
if self.leave_type:
|
||||
leave_type = frappe.get_doc("Leave Type", self.leave_type)
|
||||
if leave_type.applicable_after > 0:
|
||||
date_of_joining = frappe.db.get_value("Employee", self.employee, "date_of_joining")
|
||||
leave_days = get_approved_leaves_for_period(self.employee, False, date_of_joining, self.from_date)
|
||||
number_of_days = date_diff(getdate(self.from_date), date_of_joining)
|
||||
if number_of_days >= 0:
|
||||
holidays = 0
|
||||
if not frappe.db.get_value("Leave Type", self.leave_type, "include_holiday"):
|
||||
holidays = get_holidays(self.employee, date_of_joining, self.from_date)
|
||||
number_of_days = number_of_days - leave_days - holidays
|
||||
if number_of_days < leave_type.applicable_after:
|
||||
frappe.throw(_("{0} applicable after {1} working days").format(self.leave_type, leave_type.applicable_after))
|
||||
|
||||
def validate_dates(self):
|
||||
if self.from_date and self.to_date and (getdate(self.to_date) < getdate(self.from_date)):
|
||||
frappe.throw(_("To date cannot be before from date"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user