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:
123
app/api/routes/odoo.py
Normal file
123
app/api/routes/odoo.py
Normal file
@@ -0,0 +1,123 @@
|
||||
"""
|
||||
API Routes for Odoo Integration.
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.services.odoo_service import odoo_service
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/status")
|
||||
async def get_odoo_status(db: Session = Depends(get_db)):
|
||||
"""
|
||||
Get Odoo connection status.
|
||||
"""
|
||||
status = await odoo_service.test_connection()
|
||||
return status
|
||||
|
||||
|
||||
@router.post("/sync/products")
|
||||
async def sync_products(
|
||||
limit: int = 100,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Sync products from Odoo to local database.
|
||||
|
||||
- **limit**: Maximum number of products to sync
|
||||
"""
|
||||
result = await odoo_service.sync_products(limit=limit)
|
||||
|
||||
if not result.get("success"):
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=result.get("error", "Sync failed")
|
||||
)
|
||||
|
||||
return {
|
||||
"message": "Products synced successfully",
|
||||
**result
|
||||
}
|
||||
|
||||
|
||||
@router.post("/sync/services")
|
||||
async def sync_services(
|
||||
limit: int = 100,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Sync services from Odoo to local database.
|
||||
|
||||
- **limit**: Maximum number of services to sync
|
||||
"""
|
||||
result = await odoo_service.sync_services(limit=limit)
|
||||
|
||||
if not result.get("success"):
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=result.get("error", "Sync failed")
|
||||
)
|
||||
|
||||
return {
|
||||
"message": "Services synced successfully",
|
||||
**result
|
||||
}
|
||||
|
||||
|
||||
@router.post("/sync/leads")
|
||||
async def export_leads(db: Session = Depends(get_db)):
|
||||
"""
|
||||
Export unsynced leads to Odoo CRM.
|
||||
"""
|
||||
result = await odoo_service.export_leads_to_odoo()
|
||||
|
||||
if not result.get("success"):
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=result.get("error", "Export failed")
|
||||
)
|
||||
|
||||
return {
|
||||
"message": "Leads exported successfully",
|
||||
**result
|
||||
}
|
||||
|
||||
|
||||
@router.get("/sync/logs")
|
||||
async def get_sync_logs(
|
||||
limit: int = 20,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Get Odoo sync history.
|
||||
|
||||
- **limit**: Maximum number of logs to return
|
||||
"""
|
||||
logs = await odoo_service.get_sync_logs(limit=limit)
|
||||
return {"logs": logs, "count": len(logs)}
|
||||
|
||||
|
||||
@router.get("/sales")
|
||||
async def get_sales_summary(
|
||||
days: int = 30,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Get sales summary from Odoo.
|
||||
|
||||
- **days**: Number of days to look back
|
||||
"""
|
||||
result = await odoo_service.get_sales_summary(days=days)
|
||||
|
||||
if not result.get("success"):
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=result.get("error", "Failed to get sales data")
|
||||
)
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user