From 705384d8fe03d9f373d97c3e3094f11918804000 Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Sat, 6 Aug 2016 13:42:18 +0530 Subject: [PATCH] Leave Application Validation for processed salary --- .../hr/doctype/leave_application/leave_application.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index fee39aad3c..838d8f7513 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -36,6 +36,7 @@ class LeaveApplication(Document): self.validate_max_days() self.show_block_day_warning() self.validate_block_days() + self.validate_salary_processed_days() self.validate_leave_approver() def on_update(self): @@ -95,6 +96,15 @@ class LeaveApplication(Document): frappe.throw(_("Leave cannot be applied/cancelled before {0}, as leave balance has already been carry-forwarded in the future leave allocation record {1}") .format(formatdate(future_allocation[0].from_date), future_allocation[0].name)) + def validate_salary_processed_days(self): + last_processed_pay_slip = frappe.db.sql("""select start_date, end_date from `tabSalary Slip` + where docstatus != 2 and employee = %s and ((%s between start_date and end_date) or (%s between start_date and end_date)) order by modified desc limit 1""",(self.employee, self.to_date, self.from_date)) + + if last_processed_pay_slip: + frappe.throw(_("Salary already processed for period between {0} and {1}, Leave application period cannot be between this date range."). + format(formatdate(last_processed_pay_slip[0][0]), formatdate(last_processed_pay_slip[0][1]))) + + def show_block_day_warning(self): block_dates = get_applicable_block_dates(self.from_date, self.to_date, self.employee, self.company, all_lists=True)