feat: Add Analytics, Odoo Integration, A/B Testing, and Content features
Phase 1 - Analytics y Reportes: - PostMetrics and AnalyticsReport models for tracking engagement - Analytics service with dashboard stats, top posts, optimal times - 8 API endpoints at /api/analytics/* - Interactive dashboard with Chart.js charts - Celery tasks for metrics fetch (15min) and weekly reports Phase 2 - Integración Odoo: - Lead and OdooSyncLog models for CRM integration - Odoo fields added to Product and Service models - XML-RPC service for bidirectional sync - Lead management API at /api/leads/* - Leads dashboard template - Celery tasks for product/service sync and lead export Phase 3 - A/B Testing y Recycling: - ABTest, ABTestVariant, RecycledPost models - Statistical winner analysis using chi-square test - Content recycling with engagement-based scoring - APIs at /api/ab-tests/* and /api/recycling/* - Automated test evaluation and content recycling tasks Phase 4 - Thread Series y Templates: - ThreadSeries and ThreadPost models for multi-post threads - AI-powered thread generation - Enhanced ImageTemplate with HTML template support - APIs at /api/threads/* and /api/templates/* - Thread scheduling with reply chain support Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
116
app/models/lead.py
Normal file
116
app/models/lead.py
Normal file
@@ -0,0 +1,116 @@
|
||||
"""
|
||||
Lead Model - Leads generated from social media interactions.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, ForeignKey, JSON, Enum
|
||||
from sqlalchemy.dialects.postgresql import ARRAY
|
||||
from sqlalchemy.orm import relationship
|
||||
import enum
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class LeadStatus(enum.Enum):
|
||||
"""Lead status options."""
|
||||
NEW = "new"
|
||||
CONTACTED = "contacted"
|
||||
QUALIFIED = "qualified"
|
||||
PROPOSAL = "proposal"
|
||||
WON = "won"
|
||||
LOST = "lost"
|
||||
|
||||
|
||||
class LeadPriority(enum.Enum):
|
||||
"""Lead priority levels."""
|
||||
LOW = "low"
|
||||
MEDIUM = "medium"
|
||||
HIGH = "high"
|
||||
URGENT = "urgent"
|
||||
|
||||
|
||||
class Lead(Base):
|
||||
"""
|
||||
Lead model for tracking potential customers from social media.
|
||||
"""
|
||||
__tablename__ = "leads"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
|
||||
# Source information
|
||||
interaction_id = Column(Integer, ForeignKey("interactions.id"), nullable=True)
|
||||
platform = Column(String(50), nullable=False, index=True)
|
||||
|
||||
# Contact information
|
||||
name = Column(String(255), nullable=True)
|
||||
email = Column(String(255), nullable=True, index=True)
|
||||
phone = Column(String(50), nullable=True)
|
||||
company = Column(String(255), nullable=True)
|
||||
|
||||
# Social media info
|
||||
username = Column(String(100), nullable=True)
|
||||
profile_url = Column(String(500), nullable=True)
|
||||
|
||||
# Interest and context
|
||||
interest = Column(Text, nullable=True) # What they're interested in
|
||||
source_content = Column(Text, nullable=True) # Original interaction content
|
||||
notes = Column(Text, nullable=True)
|
||||
|
||||
# Products/services interest
|
||||
products_interested = Column(ARRAY(Integer), nullable=True) # Product IDs
|
||||
services_interested = Column(ARRAY(Integer), nullable=True) # Service IDs
|
||||
|
||||
# Status tracking
|
||||
status = Column(String(20), default="new", index=True)
|
||||
priority = Column(String(20), default="medium", index=True)
|
||||
|
||||
# Assignment
|
||||
assigned_to = Column(String(100), nullable=True)
|
||||
|
||||
# Odoo integration
|
||||
odoo_lead_id = Column(Integer, nullable=True, unique=True, index=True)
|
||||
synced_to_odoo = Column(Boolean, default=False)
|
||||
odoo_synced_at = Column(DateTime, nullable=True)
|
||||
|
||||
# Metadata
|
||||
tags = Column(ARRAY(String), nullable=True)
|
||||
custom_fields = Column(JSON, nullable=True)
|
||||
|
||||
# Timestamps
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
last_contacted_at = Column(DateTime, nullable=True)
|
||||
|
||||
# Relationship
|
||||
interaction = relationship("Interaction", backref="leads")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Lead {self.id} - {self.name or self.username}>"
|
||||
|
||||
def to_dict(self):
|
||||
"""Convert to dictionary."""
|
||||
return {
|
||||
"id": self.id,
|
||||
"interaction_id": self.interaction_id,
|
||||
"platform": self.platform,
|
||||
"name": self.name,
|
||||
"email": self.email,
|
||||
"phone": self.phone,
|
||||
"company": self.company,
|
||||
"username": self.username,
|
||||
"profile_url": self.profile_url,
|
||||
"interest": self.interest,
|
||||
"source_content": self.source_content,
|
||||
"notes": self.notes,
|
||||
"products_interested": self.products_interested,
|
||||
"services_interested": self.services_interested,
|
||||
"status": self.status,
|
||||
"priority": self.priority,
|
||||
"assigned_to": self.assigned_to,
|
||||
"odoo_lead_id": self.odoo_lead_id,
|
||||
"synced_to_odoo": self.synced_to_odoo,
|
||||
"tags": self.tags,
|
||||
"created_at": self.created_at.isoformat() if self.created_at else None,
|
||||
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
|
||||
"last_contacted_at": self.last_contacted_at.isoformat() if self.last_contacted_at else None
|
||||
}
|
||||
Reference in New Issue
Block a user