From 1d1427de60c3070f2fd6103a04c0037c45c669de Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Thu, 5 Sep 2019 15:02:33 +0530 Subject: [PATCH] fix(auto attendance): handling None case for IN/OUT Logs (#18867) --- erpnext/hr/doctype/employee_checkin/employee_checkin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/hr/doctype/employee_checkin/employee_checkin.py b/erpnext/hr/doctype/employee_checkin/employee_checkin.py index d7d6706140..86705121ac 100644 --- a/erpnext/hr/doctype/employee_checkin/employee_checkin.py +++ b/erpnext/hr/doctype/employee_checkin/employee_checkin.py @@ -142,8 +142,10 @@ def calculate_working_hours(logs, check_in_out_type, working_hours_calc_type): elif check_in_out_type == 'Strictly based on Log Type in Employee Checkin': if working_hours_calc_type == 'First Check-in and Last Check-out': - first_in_log = logs[find_index_in_dict(logs, 'log_type', 'IN')] - last_out_log = logs[len(logs)-1-find_index_in_dict(reversed(logs), 'log_type', 'OUT')] + first_in_log_index = find_index_in_dict(logs, 'log_type', 'IN') + first_in_log = logs[first_in_log_index] if first_in_log_index or first_in_log_index == 0 else None + last_out_log_index = find_index_in_dict(reversed(logs), 'log_type', 'OUT') + last_out_log = logs[len(logs)-1-last_out_log_index] if last_out_log_index or last_out_log_index == 0 else None if first_in_log and last_out_log: in_time, out_time = first_in_log.time, last_out_log.time total_hours = time_diff_in_hours(in_time, out_time)