From e50d2c16b4325d44db52f026ebfc1c2096fa89a5 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 27 May 2026 15:44:50 +0000 Subject: [PATCH] Tickets - credit first responder on owner self-close When a ticket owner closed their own ticket, record_ticket_closed skipped the staff stats block entirely, so the assigned/first-responding staff member never received tickets_closed credit, resolution time, or a TICKET_CLOSED event. The function already attributes ticket.claimed_by to the first responder when no explicit claimer exists, so route close credit to that staff member on self-close. https://claude.ai/code/session_01PcnLXE9Ek2Yu6tChjDp3Vc --- tickets/common/analytics.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tickets/common/analytics.py b/tickets/common/analytics.py index b5ec678e1..9c2c80a9b 100644 --- a/tickets/common/analytics.py +++ b/tickets/common/analytics.py @@ -187,9 +187,18 @@ def record_ticket_closed( ) ) - # --- Staff Stats (only if a staff member closed it, not self-close) --- + # --- Staff Stats --- + # If a staff member closed it, they get the credit. + # On a self-close by the owner, fall back to the attributed staff member + # (claimer, or first responder) so they still receive close credit. + staff_credit_id: int | None = None if closed_by_id != owner_id: - staff_stats = conf.get_staff_stats(closed_by_id) + staff_credit_id = closed_by_id + elif ticket.claimed_by is not None and ticket.claimed_by != owner_id: + staff_credit_id = ticket.claimed_by + + if staff_credit_id is not None: + staff_stats = conf.get_staff_stats(staff_credit_id) staff_stats.tickets_closed += 1 staff_stats.total_resolution_time += resolution_time staff_stats.resolution_count += 1