feat(crm): dominio backend (cuentas, contactos, prospectos, embudos, oportunidades, actividades)
- 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>
This commit is contained in:
40
backend/api/v1/modules/crm/accounts/models.py
Normal file
40
backend/api/v1/modules/crm/accounts/models.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from sqlalchemy import Integer, 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 Account(Base, TenantScopedMixin, TimestampMixin):
|
||||
"""Cuenta CRM: empresa cliente o prospecto.
|
||||
|
||||
Modela importadores, IMMEX, agencias aduanales, transportistas, etc.
|
||||
Los campos aduaneros (RFC, patente) son opcionales para no forzar datos
|
||||
en prospectos que aún no comparten información fiscal.
|
||||
"""
|
||||
|
||||
__tablename__ = "accounts"
|
||||
__table_args__ = {"schema": "crm"}
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
||||
# Razón social (nombre legal) y nombre comercial
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
trade_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
rfc: Mapped[str | None] = mapped_column(String(13), nullable=True, index=True)
|
||||
# Tipo de cuenta: immex | agencia_aduanal | importador | exportador | transportista | otro
|
||||
account_type: Mapped[str | None] = mapped_column(String(40), nullable=True)
|
||||
industry: Mapped[str | None] = mapped_column(String(120), nullable=True)
|
||||
email: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
phone: Mapped[str | None] = mapped_column(String(40), nullable=True)
|
||||
website: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
address: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
city: Mapped[str | None] = mapped_column(String(120), nullable=True)
|
||||
state: Mapped[str | None] = mapped_column(String(120), nullable=True)
|
||||
country: Mapped[str | None] = mapped_column(String(2), nullable=True, server_default=text("'MX'"))
|
||||
# Patente del agente aduanal (dato aduanero, no se traduce)
|
||||
patente_aduanal: Mapped[str | None] = mapped_column(String(20), nullable=True)
|
||||
# Estado comercial: active | inactive | prospect
|
||||
status: Mapped[str] = mapped_column(String(20), nullable=False, server_default=text("'active'"))
|
||||
# Vendedor responsable (id de usuario Keycloak / sub)
|
||||
owner_user_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
Reference in New Issue
Block a user