RelPromotoresPaises — fuerza_ventas.rel_promotores_paises¶
Cobertura Territorial Internacional de Promotores.
import uuid
from datetime import datetime
from typing import Optional
from sqlalchemy import (
BigInteger,
Boolean,
ForeignKeyConstraint,
Index,
UniqueConstraint,
text,
)
from sqlalchemy.dialects.postgresql import TIMESTAMP, UUID
from sqlalchemy.orm import Mapped, mapped_column
from app.db.base import Base
class RelPromotoresPaises(Base):
"""
Cobertura Territorial Internacional de Promotores.
Países autorizados para la operación y venta de promotores
internacionales o de exportación.
Legacy:
i142t_promotor_pais
"""
__tablename__ = "rel_promotores_paises"
__table_args__ = (
UniqueConstraint(
"empresa_id",
"id",
name="uq_rel_promotores_paises_empresa_id",
),
UniqueConstraint(
"empresa_id",
"promotor_id",
"pais_id",
name="uq_rel_promotores_paises_asignacion",
),
ForeignKeyConstraint(
["empresa_id", "promotor_id"],
["fuerza_ventas.mae_promotores.empresa_id", "fuerza_ventas.mae_promotores.id"],
ondelete="CASCADE",
name="fk_rel_promotores_paises_promotor",
),
Index(
"ix_rel_promotores_paises_empresa_activo",
"empresa_id",
"is_activo",
),
Index(
"ix_rel_promotores_paises_empresa_promotor",
"empresa_id",
"promotor_id",
),
Index(
"ix_rel_promotores_paises_empresa_pais",
"empresa_id",
"pais_id",
),
{
"schema": "fuerza_ventas",
"comment": "Cobertura Territorial Internacional de Promotores",
},
)
id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
primary_key=True,
server_default=text("gen_random_uuid()"),
comment="Identificador único UUID",
)
empresa_id: Mapped[int] = mapped_column(
BigInteger,
nullable=False,
comment="Identificador BIGINT de la empresa en core.identidad (RLS)",
)
promotor_id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
nullable=False,
comment="Promotor asignado",
)
pais_id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
nullable=False,
comment="Correlación lógica con core.identidad.mae_paises (sin FK física)",
)
is_activo: Mapped[bool] = mapped_column(
Boolean,
nullable=False,
server_default=text("true"),
comment="Estado lógico del registro",
)
created_at: Mapped[datetime] = mapped_column(
TIMESTAMP(timezone=True),
nullable=False,
server_default=text("now()"),
comment="Fecha de creación",
)
updated_at: Mapped[datetime] = mapped_column(
TIMESTAMP(timezone=True),
nullable=False,
server_default=text("now()"),
comment="Fecha de última actualización",
)
deleted_at: Mapped[Optional[datetime]] = mapped_column(
TIMESTAMP(timezone=True),
nullable=True,
comment="Fecha de eliminación lógica",
)
created_by: Mapped[Optional[uuid.UUID]] = mapped_column(
UUID(as_uuid=True),
nullable=True,
comment="Usuario creador",
)
updated_by: Mapped[Optional[uuid.UUID]] = mapped_column(
UUID(as_uuid=True),
nullable=True,
comment="Usuario modificador",
)