Updated TA exporting function

This commit is contained in:
2025-10-15 15:10:54 -04:00
parent e3dd7ad790
commit df34f67c91
+11 -7
View File
@@ -7647,15 +7647,21 @@ def export_time_attendance_excel(records, project_name_for_filename, date_range_
cell.fill = missed_punch_fill cell.fill = missed_punch_fill
current_row += 1 current_row += 1
else: else:
# Multiple records same location - show pairs with Missed Punch and ORANGE background # Multiple records same location - show pairs, only mark unpaired records as Missed Punch
# Show pairs in same row (In and Out), last unpaired record gets its own row # Show pairs in same row (In and Out), last unpaired record gets its own row
num_complete_pairs = len(sorted_records) // 2 num_complete_pairs = len(sorted_records) // 2
# Write complete pairs (2 records per row) # Write complete pairs (2 records per row) - these are NOT missed punches
for i in range(0, num_complete_pairs * 2, 2): for i in range(0, num_complete_pairs * 2, 2):
check_in_record = sorted_records[i] check_in_record = sorted_records[i]
check_out_record = sorted_records[i + 1] check_out_record = sorted_records[i + 1]
# Calculate hours for this complete pair
pair_datetime_in = datetime.combine(date_obj, check_in_record.check_in_time)
pair_datetime_out = datetime.combine(date_obj, check_out_record.check_in_time)
pair_hours = (pair_datetime_out - pair_datetime_in).total_seconds() / 3600.0
pair_hours = round(pair_hours, 2)
row_data = [ row_data = [
date_obj.strftime('%A').upper(), date_obj.strftime('%A').upper(),
date_obj.strftime('%m/%d/%Y'), date_obj.strftime('%m/%d/%Y'),
@@ -7663,7 +7669,7 @@ def export_time_attendance_excel(records, project_name_for_filename, date_range_
check_out_record.check_in_time.strftime('%I:%M:%S %p'), # Out check_out_record.check_in_time.strftime('%I:%M:%S %p'), # Out
check_in_record.location_name, check_in_record.location_name,
'', '',
'Missed Punch', pair_hours, # Show calculated hours instead of Missed Punch
'', # Daily Total shown only on last row '', # Daily Total shown only on last row
'', '',
'', '',
@@ -7677,9 +7683,7 @@ def export_time_attendance_excel(records, project_name_for_filename, date_range_
cell = ws.cell(row=current_row, column=col, value=value) cell = ws.cell(row=current_row, column=col, value=value)
cell.font = data_font cell.font = data_font
cell.border = border cell.border = border
# Apply orange background to Missed Punch cell (column G) # No orange background for complete pairs
if col == 7:
cell.fill = missed_punch_fill
current_row += 1 current_row += 1
# Write the last unpaired record if odd number of records # Write the last unpaired record if odd number of records
@@ -7718,7 +7722,7 @@ def export_time_attendance_excel(records, project_name_for_filename, date_range_
out_time, out_time,
last_record.location_name, last_record.location_name,
'', '',
'Missed Punch', 'Missed Punch', # Only THIS unpaired record shows Missed Punch
daily_total_display, # Show Daily Total on last row daily_total_display, # Show Daily Total on last row
'', '',
'', '',