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

feat(Shift Type): Auto update Last Sync of Checkin #2513

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions hrms/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
"hrms.hr.doctype.daily_work_summary_group.daily_work_summary_group.trigger_emails",
],
"hourly_long": [
"hrms.hr.doctype.shift_type.shift_type.update_last_sync_of_checkin",
"hrms.hr.doctype.shift_type.shift_type.process_auto_attendance_for_all_shifts",
"hrms.hr.doctype.shift_assignment_schedule.shift_assignment_schedule.process_auto_shift_creation",
],
Expand Down
13 changes: 11 additions & 2 deletions hrms/hr/doctype/shift_type/shift_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"working_hours_threshold_for_absent",
"process_attendance_after",
"last_sync_of_checkin",
"auto_update_last_sync",
"grace_period_settings_auto_attendance_section",
"enable_late_entry_marking",
"late_entry_grace_period",
Expand Down Expand Up @@ -146,7 +147,8 @@
"description": "Last Known Successful Sync of Employee Checkin. Reset this only if you are sure that all Logs are synced from all the locations. Please don't modify this if you are unsure.",
"fieldname": "last_sync_of_checkin",
"fieldtype": "Datetime",
"label": "Last Sync of Checkin"
"label": "Last Sync of Checkin",
"read_only_depends_on": "auto_update_last_sync"
},
{
"default": "0",
Expand All @@ -173,10 +175,17 @@
"fieldtype": "Select",
"label": "Roster Color",
"options": "Blue\nCyan\nFuchsia\nGreen\nLime\nOrange\nPink\nRed\nViolet\nYellow"
},
{
"default": "0",
"description": "Recommended for a single biometric device / checkins via mobile app",
"fieldname": "auto_update_last_sync",
"fieldtype": "Check",
"label": "Automatically update Last Sync of Checkin"
}
],
"links": [],
"modified": "2024-05-17 15:48:27.191003",
"modified": "2024-12-17 13:04:38.663410",
"modified_by": "Administrator",
"module": "HR",
"name": "Shift Type",
Expand Down
17 changes: 17 additions & 0 deletions hrms/hr/doctype/shift_type/shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,24 @@ def should_mark_attendance(self, employee: str, attendance_date: str) -> bool:
return True


def update_last_sync_of_checkin():
"""Called from hooks"""
shifts = frappe.get_all(
"Shift Type",
filters={"enable_auto_attendance": 1, "auto_update_last_sync": 1},
fields=["name", "last_sync_of_checkin"],
)

for shift in shifts:
last_shift_sync = frappe.db.get_value(
"Employee Checkin", {"shift": shift.name}, "time", order_by="time desc"
)
if get_datetime(last_shift_sync) > get_datetime(shift.last_sync_of_checkin):
frappe.db.set_value("Shift Type", shift.name, "last_sync_of_checkin", last_shift_sync)


def process_auto_attendance_for_all_shifts():
"""Called from hooks"""
shift_list = frappe.get_all("Shift Type", filters={"enable_auto_attendance": "1"}, pluck="name")
for shift in shift_list:
doc = frappe.get_cached_doc("Shift Type", shift)
Expand Down
Loading