I have two consecutive checkin how to choose latest checkin instead of first checkin for attendance .
Add “order by name desc” to the query.
I will affect remaining check-in data
How are you fetching the data? If you share your code or query, it will be easier to understand.
frappe.get_all(
“Employee Checkin”,
fields=[
“name”,
“employee”,
“log_type”,
“time”,
“shift”,
“shift_start”,
“shift_end”,
“shift_actual_start”,
“shift_actual_end”,
“device_id”,
],
filters={
“skip_auto_attendance”: 0,
“attendance”: (“is”, “not set”),
“time”: (“>=”, self.process_attendance_after),
“shift_actual_end”: (“<”, self.last_sync_of_checkin),
“shift”: self.name,
},
order_by=“employee,time”,
)
change this to order_by="employee,time desc",
you will get latest checkin in the group
Check in - 9:00
check out -11:00
check in - 11:10
check out - 13:50
check in -14:01
check in -14:21
check out - 16:00
check in : 16:20
check out -18:00
I want check in -14:21 instead of 14:01.remaining data i want in that order only
Hi @thakir , please check this code
# Sample input data
logs = [
{'log_type': 'IN', 'time': '9:00'},
{'log_type': 'OUT', 'time': '11:00'},
{'log_type': 'IN', 'time': '11:10'},
{'log_type': 'OUT', 'time': '13:50'},
{'log_type': 'IN', 'time': '14:01'}, # This one we want to replace with 14:21
{'log_type': 'IN', 'time': '14:21'}, # This is the later check-in
{'log_type': 'OUT', 'time': '16:00'},
{'log_type': 'IN', 'time': '16:20'},
{'log_type': 'OUT', 'time': '18:00'}
]
last_log = None
result = []
for log in logs:
if last_log == log['log_type']:
del result[-1]
result.append(log)
last_log = log['log_type']
for log in result:
print(f"{log['log_type']} - {log['time']}")