Saltar a contenido

Banco — core.identidad.cat_bancos

Catálogo de instituciones bancarias y financieras por empresa para operaciones contables, financieras y de recaudación.

from datetime import datetime, date
from typing import Optional
import uuid

from sqlalchemy import (
    BigInteger,
    Boolean,
    CheckConstraint,
    Date,
    DateTime,
    ForeignKey,
    Identity,
    Index,
    Integer,
    SmallInteger,
    String,
    Text,
    UniqueConstraint,
    text,
)
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column


class Base(DeclarativeBase):
    pass

class CatBanco(Base):
    __tablename__ = 'cat_bancos'
    __table_args__ = (
        UniqueConstraint('empresa_id', 'id', name='uq_cat_bancos_empresa_id'),
        UniqueConstraint('empresa_id', 'codigo', name='uq_cat_bancos_empresa_codigo'),
        Index('ix_cat_bancos_empresa_activo', 'empresa_id', 'is_activo'),
        {"schema": 'core.identidad'},
    )

    id: Mapped[uuid.UUID] = mapped_column(
        UUID(as_uuid=True),
        primary_key=True,
        server_default=text("gen_random_uuid()"),
    )
    empresa_id: Mapped[int] = mapped_column(
        BigInteger,
        nullable=False,
        comment='Empresa a la que pertenece el banco',
    )
    codigo: Mapped[str] = mapped_column(
        String(20),
        nullable=False,
        comment='Código de la institución bancaria',
    )
    nombre: Mapped[str] = mapped_column(
        String(100),
        nullable=False,
        comment='Nombre de la institución bancaria',
    )

    # Auditoría General
    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(
        DateTime(timezone=True),
        nullable=False,
        server_default=text("now()"),
        comment='Fecha de creación',
    )
    updated_at: Mapped[datetime] = mapped_column(
        DateTime(timezone=True),
        nullable=False,
        server_default=text("now()"),
        comment='Fecha de última actualización',
    )
    deleted_at: Mapped[datetime | None] = mapped_column(
        DateTime(timezone=True),
        comment='Fecha de eliminación lógica',
    )
    created_by: Mapped[uuid.UUID | None] = mapped_column(
        UUID(as_uuid=True),
        comment='Usuario creador',
    )
    updated_by: Mapped[uuid.UUID | None] = mapped_column(
        UUID(as_uuid=True),
        comment='Usuario modificador',
    )