Include healthy in lifecycle_status_counts so frontend doesn’t infer from merchant_status_counts
Repo: · Issue: #1082 Status: Open · Priority: P2 Assignee: Sparsh
Description
Summary
Today the API returns:
- merchant_status_counts: counts by funnel status (e.g.
approved,active,in_review, …). - lifecycle_status_counts: only
activation_overdue,dormant, andchurned.
“Healthy” merchants are those with processing status = null (see app/api/merchants_kpis.py: the status calc uses ELSE 'null' for healthy). The frontend currently has to infer the healthy count by combining these two sources (e.g. post-approval statuses minus the three lifecycle buckets), which is fragile and duplicates lifecycle logic on the client.
Goal: Add a healthy key inside lifecycle_status_counts (e.g. { activation_overdue: 2, dormant: 11, churned: 0, healthy: 31 }) so that:
- Lifecycle logic stays server-side.
- The API is self-consistent: every lifecycle status, including healthy, comes from the same source of truth.
- The frontend no longer needs to infer healthy from two separate fields.
Current behaviour
- Lifecycle status is computed in
calculate_processing_status_for_all_merchants()inapp/api/merchants_kpis.pyand stored inmerchant_kpiwithmetric_label = PROCESSING_STATUSandcategorical_valueinactivation_overdue|dormant|churned|null(null = healthy). - In
app/api/master_partners_router.py,fetch_partners_stats():- Builds lifecycle_status_counts from a query that excludes
categorical_value = 'null'(seelifecycle_status_queryfilters around lines 205–207). - Initializes only
activation_overdue,dormant,churnedinget_stat_entry()(lines 317–321). - So “healthy” is never present in lifecycle_status_counts.
- Builds lifecycle_status_counts from a query that excludes
Suggested backend changes
app/api/master_partners_router.py- Include healthy in the lifecycle query: Remove the filter that excludes
categorical_value = 'null'(or explicitly include it) so that rows withcategorical_value = 'null'are grouped and counted. - Initialize
healthyin the stats dict: I
- Include healthy in the lifecycle query: Remove the filter that excludes
Implementation Notes
Dash adds notes here while working
Related
Link to people, meetings, dependent tickets