- Nuevo schema `crm` con 7 tablas multi-tenant (TenantScopedMixin + soft delete) - Módulos FastAPI por dominio: models/dto/service/routes (patrón example) - Métricas del dashboard (KPIs + embudo por etapa) - Conversión de prospecto → cuenta/contacto/oportunidad (idempotente) - Movimiento de oportunidad entre etapas (Kanban) con estado/probabilidad derivados - 25 permisos registrados en PermissionRegistry - Migración Alembic con upgrade/downgrade completos - 24 tests de servicios (pytest) en verde Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
36 lines
1.8 KiB
Python
36 lines
1.8 KiB
Python
from sqlalchemy import ForeignKey, Integer, Numeric, String, Text, text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from api.v1.common.base_models import TenantScopedMixin, TimestampMixin
|
|
from core.database import Base
|
|
|
|
|
|
class Lead(Base, TenantScopedMixin, TimestampMixin):
|
|
"""Prospecto sin calificar. Al calificarse se convierte en cuenta/contacto/oportunidad."""
|
|
|
|
__tablename__ = "leads"
|
|
__table_args__ = {"schema": "crm"}
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
contact_name: Mapped[str | None] = mapped_column(String(160), nullable=True)
|
|
email: Mapped[str | None] = mapped_column(String(255), nullable=True, index=True)
|
|
phone: Mapped[str | None] = mapped_column(String(40), nullable=True)
|
|
company_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
# Origen: web | referido | evento | llamada | email | otro
|
|
source: Mapped[str | None] = mapped_column(String(60), nullable=True)
|
|
# Estado: new | contacted | qualified | unqualified | converted
|
|
status: Mapped[str] = mapped_column(String(20), nullable=False, server_default=text("'new'"), index=True)
|
|
estimated_value: Mapped[float | None] = mapped_column(Numeric(14, 2), nullable=True)
|
|
owner_user_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
|
converted_account_id: Mapped[int | None] = mapped_column(
|
|
Integer, ForeignKey("crm.accounts.id"), nullable=True
|
|
)
|
|
converted_contact_id: Mapped[int | None] = mapped_column(
|
|
Integer, ForeignKey("crm.contacts.id"), nullable=True
|
|
)
|
|
converted_opportunity_id: Mapped[int | None] = mapped_column(
|
|
Integer, ForeignKey("crm.opportunities.id"), nullable=True
|
|
)
|
|
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|