Spaces:
Running

axeronis commited on
Commit
54f6d62
·
1 Parent(s): f5aa712

fix(backend): Fix AttributeError by inferring lead source from contact fields

Browse files
backend/app/services/analytics_service.py CHANGED
@@ -579,7 +579,16 @@ class AnalyticsService:
579
  channel_counts = {}
580
 
581
  for lead in leads:
582
- source = lead.source if lead.source else "manual"
 
 
 
 
 
 
 
 
 
583
  channel_counts[source] = channel_counts.get(source, 0) + 1
584
 
585
  # Нормализация имен каналов для display
 
579
  channel_counts = {}
580
 
581
  for lead in leads:
582
+ # Infer source from contact fields
583
+ source = "manual"
584
+ if lead.telegram_id:
585
+ source = "telegram"
586
+ elif lead.whatsapp_id:
587
+ source = "whatsapp"
588
+ elif lead.linkedin_urn or lead.linkedin_profile:
589
+ source = "linkedin"
590
+ elif lead.email:
591
+ source = "email"
592
  channel_counts[source] = channel_counts.get(source, 0) + 1
593
 
594
  # Нормализация имен каналов для display