"""Datos fiscales del emisor — ``fin.issuer_settings``. Es la identidad fiscal con la que la empresa emite CFDI: razón social, RFC, régimen fiscal y código postal del lugar de expedición. Hay **una sola configuración vigente por empresa**, garantizada con un índice único parcial. """ from sqlalchemy import ForeignKey, Index, Integer, String, text from sqlalchemy.orm import Mapped, mapped_column, relationship from api.v1.common.base_models import TenantScopedMixin, TimestampMixin from core.database import Base from ..catalogs.models import TaxRegime # noqa: F401 (resuelve la relación) _ALIVE = text("deleted_at IS NULL") class IssuerSettings(Base, TenantScopedMixin, TimestampMixin): """Configuración fiscal del emisor de la empresa.""" __tablename__ = "issuer_settings" __table_args__ = ( Index( "uq_fin_issuer_settings_company", "tenant_id", "company_id", unique=True, postgresql_where=_ALIVE, sqlite_where=_ALIVE, ), {"schema": "fin"}, ) id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True) legal_name: Mapped[str] = mapped_column(String(255), nullable=False) # razón social rfc: Mapped[str] = mapped_column(String(13), nullable=False) tax_regime_id: Mapped[int] = mapped_column( Integer, ForeignKey("sat.tax_regimes.id"), nullable=False, index=True ) # CP del lugar de expedición del comprobante zip_code: Mapped[str | None] = mapped_column(String(5), nullable=True) updated_by: Mapped[str | None] = mapped_column(String(64), nullable=True) tax_regime: Mapped["TaxRegime"] = relationship("TaxRegime", lazy="selectin")