Cancel attendance if leave application is cancelled (#14372)
* Cancel attendance if leave application is cancelled
* Fix as per review
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index e03764a..eb5aec6 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -60,6 +60,7 @@
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 @@
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