From b9399d878196f1f71d5fe49e190a9111bf29c899 Mon Sep 17 00:00:00 2001 From: Shreya Shah Date: Fri, 8 Jun 2018 11:24:08 +0530 Subject: [PATCH] Cancel attendance if leave application is cancelled (#14372) * Cancel attendance if leave application is cancelled * Fix as per review --- erpnext/hr/doctype/leave_application/leave_application.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index e03764a43f..eb5aec604d 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -60,6 +60,7 @@ class LeaveApplication(Document): def on_cancel(self): # notify leave applier about cancellation self.notify_employee("cancelled") + self.cancel_attendance() def validate_dates(self): if self.from_date and self.to_date and (getdate(self.to_date) < getdate(self.from_date)): @@ -138,6 +139,13 @@ class LeaveApplication(Document): doc.insert(ignore_permissions=True) doc.submit() + def cancel_attendance(self): + if self.docstatus == 2: + attendance = frappe.db.sql("""select name from `tabAttendance` where employee = %s\ + and (attendance_date between %s and %s) and docstatus < 2 and status in ('On Leave', 'Half Day')""",(self.employee, self.from_date, self.to_date), as_dict=1) + for name in attendance: + frappe.db.set_value("Attendance", name, "docstatus", 2) + def validate_salary_processed_days(self): if not frappe.db.get_value("Leave Type", self.leave_type, "is_lwp"): return