Files
CRM_AGENTES_CARGA/backend/api/v1/modules/crm/leads/dto.py
Aduanasoft 088a8fc4df 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>
2026-07-14 09:32:05 -06:00

71 lines
2.2 KiB
Python

from datetime import datetime
from decimal import Decimal
from pydantic import BaseModel, ConfigDict, EmailStr, Field
class LeadCreate(BaseModel):
name: str = Field(..., min_length=1, max_length=255)
contact_name: str | None = Field(None, max_length=160)
email: EmailStr | None = None
phone: str | None = Field(None, max_length=40)
company_name: str | None = Field(None, max_length=255)
source: str | None = Field(None, max_length=60)
status: str = Field("new", max_length=20)
estimated_value: Decimal | None = Field(None, ge=0, max_digits=14, decimal_places=2)
owner_user_id: str | None = Field(None, max_length=64)
notes: str | None = None
class LeadUpdate(BaseModel):
name: str | None = Field(None, min_length=1, max_length=255)
contact_name: str | None = Field(None, max_length=160)
email: EmailStr | None = None
phone: str | None = Field(None, max_length=40)
company_name: str | None = Field(None, max_length=255)
source: str | None = Field(None, max_length=60)
status: str | None = Field(None, max_length=20)
estimated_value: Decimal | None = Field(None, ge=0, max_digits=14, decimal_places=2)
owner_user_id: str | None = Field(None, max_length=64)
notes: str | None = None
class LeadConvert(BaseModel):
"""Parámetros de conversión de un prospecto."""
create_opportunity: bool = True
opportunity_name: str | None = Field(None, max_length=255)
pipeline_id: int | None = None
stage_id: int | None = None
amount: Decimal | None = Field(None, ge=0, max_digits=14, decimal_places=2)
class LeadResponse(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: int
name: str
contact_name: str | None
email: str | None
phone: str | None
company_name: str | None
source: str | None
status: str
estimated_value: Decimal | None
owner_user_id: str | None
converted_account_id: int | None
converted_contact_id: int | None
converted_opportunity_id: int | None
notes: str | None
tenant_id: int
company_id: int
created_at: datetime
updated_at: datetime
class LeadConvertResult(BaseModel):
lead: LeadResponse
account_id: int
contact_id: int | None
opportunity_id: int | None