MaePresupuestosCliente — fuerza_ventas.mae_presupuestos_cliente¶
Presupuestos Comerciales por Cliente y Promotor.
import uuid
from datetime import datetime
from decimal import Decimal
from typing import Optional
from sqlalchemy import (
BigInteger,
Boolean,
CheckConstraint,
ForeignKeyConstraint,
Index,
Integer,
Numeric,
UniqueConstraint,
text,
)
from sqlalchemy.dialects.postgresql import TIMESTAMP, UUID
from sqlalchemy.orm import Mapped, mapped_column
from app.db.base import Base
class MaePresupuestosCliente(Base):
"""
Presupuestos Comerciales por Cliente y Promotor.
Presupuesto y proyección mensual de ventas acordado para un cliente
específico atendido por un promotor.
Legacy:
i714t_presupuesto_cliente
"""
__tablename__ = "mae_presupuestos_cliente"
__table_args__ = (
UniqueConstraint(
"empresa_id",
"id",
name="uq_mae_presupuestos_cliente_empresa_id",
),
UniqueConstraint(
"empresa_id",
"cliente_id",
"promotor_id",
"anio",
"mes",
name="uq_mae_presupuestos_cliente_periodo",
),
CheckConstraint(
"mes BETWEEN 1 AND 12",
name="ck_mae_presupuestos_cliente_mes",
),
ForeignKeyConstraint(
["empresa_id", "promotor_id"],
["fuerza_ventas.mae_promotores.empresa_id", "fuerza_ventas.mae_promotores.id"],
ondelete="CASCADE",
name="fk_mae_presupuestos_cliente_promotor",
),
Index(
"ix_mae_presupuestos_cliente_empresa_activo",
"empresa_id",
"is_activo",
),
Index(
"ix_mae_presupuestos_cliente_empresa_periodo",
"empresa_id",
"anio",
"mes",
),
Index(
"ix_mae_presupuestos_cliente_empresa_cliente",
"empresa_id",
"cliente_id",
),
Index(
"ix_mae_presupuestos_cliente_empresa_promotor",
"empresa_id",
"promotor_id",
),
{
"schema": "fuerza_ventas",
"comment": "Presupuestos Comerciales por Cliente y Promotor",
},
)
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)",
)
cliente_id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
nullable=False,
comment="Cliente comercial asignado",
)
promotor_id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
nullable=False,
comment="Promotor responsable de la atención",
)
anio: Mapped[int] = mapped_column(
Integer,
nullable=False,
comment="Año fiscal del presupuesto",
)
mes: Mapped[int] = mapped_column(
Integer,
nullable=False,
comment="Mes del presupuesto (1-12)",
)
monto_presupuesto: Mapped[Decimal] = mapped_column(
Numeric(12, 2),
nullable=False,
server_default=text("0.00"),
comment="Monto mensual proyectado de compra",
)
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",
)