Skip to content

Commit

Permalink
feat(Shift Assignment): add validations for checking linked employee …
Browse files Browse the repository at this point in the history
…checkins and attendance before cancelling
  • Loading branch information
krantheman committed Jun 27, 2024
1 parent 8d19962 commit b7013b0
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions hrms/hr/doctype/shift_assignment/shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,44 @@ def on_update_after_submit(self):
self.validate_from_to_dates("start_date", "end_date")
self.validate_overlapping_shifts()

def on_cancel(self):
self.validate_employee_checkin()
self.validate_attendance()

def validate_employee_checkin(self):
checkins = frappe.get_all(
"Employee Checkin",
filters={
"employee": self.employee,
"shift": self.shift_type,
"time": ["between", [self.start_date, self.end_date]],
},
pluck="name",
)
if checkins:
frappe.throw(
_("Cannot cancel Shift Assignment: {0} as it is linked to Employee Checkin: {1}").format(
self.name, get_link_to_form("Employee Checkin", checkins[0])
)
)

def validate_attendance(self):
attendances = frappe.get_all(
"Attendance",
filters={
"employee": self.employee,
"shift": self.shift_type,
"attendance_date": ["between", [self.start_date, self.end_date]],
},
pluck="name",
)
if attendances:
frappe.throw(
_("Cannot cancel Shift Assignment: {0} as it is linked to Attendance: {1}").format(
self.name, get_link_to_form("Attendance", attendances[0])
)
)

def validate_overlapping_shifts(self):
if self.status == "Inactive":
return
Expand Down

0 comments on commit b7013b0

Please sign in to comment.