Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(UX): record reason for skipping attendance or marking absent for auto attendance #30844

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 44 additions & 13 deletions erpnext/hr/doctype/employee_checkin/employee_checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import cint, get_datetime
from frappe.utils import cint, get_datetime, get_link_to_form

from erpnext.hr.doctype.attendance.attendance import (
get_duplicate_attendance_record,
Expand Down Expand Up @@ -130,14 +130,11 @@ def mark_attendance_and_link_log(
"""
log_names = [x.name for x in logs]
employee = logs[0].employee

if attendance_status == "Skip":
frappe.db.sql(
"""update `tabEmployee Checkin`
set skip_auto_attendance = %s
where name in %s""",
("1", log_names),
)
skip_attendance_in_checkins(log_names)
return None

elif attendance_status in ("Present", "Absent", "Half Day"):
employee_doc = frappe.get_doc("Employee", employee)
duplicate = get_duplicate_attendance_record(employee, attendance_date, shift)
Expand All @@ -159,6 +156,12 @@ def mark_attendance_and_link_log(
}
attendance = frappe.get_doc(doc_dict).insert()
attendance.submit()

if attendance_status == "Absent":
attendance.add_comment(
text=_("Employee was marked Absent for not meeting the working hours threshold.")
)

frappe.db.sql(
"""update `tabEmployee Checkin`
set attendance = %s
Expand All @@ -167,13 +170,10 @@ def mark_attendance_and_link_log(
)
return attendance
else:
frappe.db.sql(
"""update `tabEmployee Checkin`
set skip_auto_attendance = %s
where name in %s""",
("1", log_names),
)
skip_attendance_in_checkins(log_names)
add_comment_in_checkins(log_names, duplicate, overlapping)
return None

else:
frappe.throw(_("{} is an invalid Attendance Status.").format(attendance_status))

Expand Down Expand Up @@ -241,3 +241,34 @@ def time_diff_in_hours(start, end):

def find_index_in_dict(dict_list, key, value):
return next((index for (index, d) in enumerate(dict_list) if d[key] == value), None)


def add_comment_in_checkins(log_names, duplicate, overlapping):
if duplicate:
text = _("Auto Attendance skipped due to duplicate attendance record: {}").format(
get_link_to_form("Attendance", duplicate[0].name)
)
else:
text = _("Auto Attendance skipped due to overlapping attendance record: {}").format(
get_link_to_form("Attendance", overlapping.name)
)

for name in log_names:
frappe.get_doc(
{
"doctype": "Comment",
"comment_type": "Comment",
"reference_doctype": "Employee Checkin",
"reference_name": name,
"content": text,
}
).insert(ignore_permissions=True)


def skip_attendance_in_checkins(log_names):
EmployeeCheckin = frappe.qb.DocType("Employee Checkin")
(
frappe.qb.update(EmployeeCheckin)
.set("skip_auto_attendance", 1)
.where(EmployeeCheckin.name.isin(log_names))
).run()
12 changes: 11 additions & 1 deletion erpnext/hr/doctype/shift_type/shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,17 @@ def mark_absent_for_dates_with_no_attendance(self, employee):
shift_details = get_employee_shift(employee, timestamp, True)

if shift_details and shift_details.shift_type.name == self.name:
mark_attendance(employee, date, "Absent", self.name)
attendance = mark_attendance(employee, date, "Absent", self.name)
if attendance:
frappe.get_doc(
{
"doctype": "Comment",
"comment_type": "Comment",
"reference_doctype": "Attendance",
"reference_name": attendance,
"content": frappe._("Employee was marked Absent due to missing Employee Checkins."),
}
).insert(ignore_permissions=True)

def get_start_and_end_dates(self, employee):
"""Returns start and end dates for checking attendance and marking absent
Expand Down