Saltar a contenido

UbicacionesPromotores — fuerza_ventas.log_ubicaciones_promotores

telemetría GPS en ruta

from datetime import datetime
from decimal import Decimal
import uuid
from typing import Optional
from sqlalchemy import String, Boolean, DateTime, BigInteger, ForeignKey, ForeignKeyConstraint, UniqueConstraint, Index, Numeric, Integer, Text
from sqlalchemy.dialects.postgresql import UUID, JSONB
from sqlalchemy.orm import Mapped, mapped_column, DeclarativeBase

class Base(DeclarativeBase):
    pass

class UbicacionesPromotores(Base):
    __tablename__ = 'log_ubicaciones_promotores'
    __table_args__ = (
        UniqueConstraint('empresa_id', 'id', name='uq_log_ubicaciones_promotores_empresa_id'),
        Index('ix_log_ubicaciones_promotores_empresa_promotor', 'empresa_id', 'promotor_id'),
        ForeignKeyConstraint(['empresa_id', 'promotor_id'], ['fuerza_ventas.mae_promotores.empresa_id', 'fuerza_ventas.mae_promotores.id'], ondelete='RESTRICT', name='fk_log_ubicaciones_promotores_promotor_id'),
        Index('ix_log_ubicaciones_promotores_empresa_activo', 'empresa_id', 'is_activo'),
        {'schema': 'fuerza_ventas'}
    )

    id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    empresa_id: Mapped[int] = mapped_column(
        BigInteger, nullable=False)
    promotor_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), nullable=False)
    latitud: Mapped[Decimal] = mapped_column(Numeric(10, 7), nullable=False)
    longitud: Mapped[Decimal] = mapped_column(Numeric(10, 7), nullable=False)
    precision_gps_metros: Mapped[Optional[Decimal]] = mapped_column(Numeric(6, 2), nullable=True)
    bateria_porcentaje: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
    is_en_movimiento: Mapped[Optional[bool]] = mapped_column(Boolean, default=True, nullable=True)
    fecha_hora_dispositivo: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)

    # Auditoría
    is_activo: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
    created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=datetime.utcnow, nullable=False)
    updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
    deleted_at: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True), nullable=True)
    created_by: Mapped[Optional[uuid.UUID]] = mapped_column(UUID(as_uuid=True), nullable=True)
    updated_by: Mapped[Optional[uuid.UUID]] = mapped_column(UUID(as_uuid=True), nullable=True)