- Enhanced TenantMiddleware to validate tenant information from JWT tokens. - Added LicenseValidationMiddleware to check tenant licenses before processing requests. - Updated security utilities to extract tenant information from tokens and validate company access. - Introduced CompanyStore to manage active company state and handle company switching in the frontend. - Modified API routes to include company_id in requests for better resource management. - Improved logging and error handling throughout the middleware and API layers. - Updated frontend components to reflect changes in company management and selection. - Added new API route for fetching user's companies with proper authentication handling.
81 lines
2.7 KiB
Python
81 lines
2.7 KiB
Python
from typing import TYPE_CHECKING
|
|
from sqlalchemy import (
|
|
Date,
|
|
DateTime,
|
|
ForeignKeyConstraint,
|
|
Index,
|
|
Integer,
|
|
PrimaryKeyConstraint,
|
|
SmallInteger,
|
|
String,
|
|
Time,
|
|
UniqueConstraint,
|
|
func,
|
|
text,
|
|
)
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.orm.base import Mapped
|
|
from datetime import datetime, time as Time2, date as Date2
|
|
from core.database import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from api.v1.modules.a76.pedmientos.models.pedimentos import Pedimentos
|
|
|
|
|
|
class PedimentoPayments(Base):
|
|
__tablename__ = "pedimento_payments"
|
|
__table_args__ = (
|
|
PrimaryKeyConstraint("id", name="pedimento_payments_pkey"),
|
|
ForeignKeyConstraint(
|
|
["tenant_id"], ["a76.tenants.id"], name="fk_pedimento_payments_tenant"
|
|
),
|
|
ForeignKeyConstraint(
|
|
["company_id"], ["a76.company.id"], name="fk_pedimento_payments_company"
|
|
),
|
|
ForeignKeyConstraint(
|
|
["pedimento_id"],
|
|
["a76.pedimentos.id"],
|
|
ondelete="CASCADE",
|
|
name="fk_pedimento_payments",
|
|
),
|
|
UniqueConstraint(
|
|
"tenant_id",
|
|
"company_id",
|
|
"pedimento_id",
|
|
name="pedimento_payments_pedimento_id_key",
|
|
),
|
|
Index("idx_pedimento_payments_pedimento_id", "pedimento_id"),
|
|
{"schema": "a76"},
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer)
|
|
tenant_id: Mapped[int] = mapped_column(Integer, nullable=False, index=True)
|
|
company_id: Mapped[int] = mapped_column(Integer, nullable=False, index=True)
|
|
pedimento_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
payment_id: Mapped[int] = mapped_column(Integer)
|
|
|
|
acknowledgment: Mapped[str] = mapped_column(String(20))
|
|
operation_number: Mapped[str] = mapped_column(String(14))
|
|
bank_code: Mapped[int] = mapped_column(Integer)
|
|
cashier: Mapped[str] = mapped_column(String(2))
|
|
date: Mapped[Date2] = mapped_column(Date)
|
|
time: Mapped[Time2] = mapped_column(Time)
|
|
shift: Mapped[str] = mapped_column(String(1))
|
|
total_cash_paid: Mapped[int] = mapped_column(Integer)
|
|
total_contributions: Mapped[int] = mapped_column(Integer)
|
|
counter_payment: Mapped[int] = mapped_column(SmallInteger)
|
|
pece_code: Mapped[str] = mapped_column(String(5))
|
|
|
|
# Timestamps
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime, nullable=False, default=func.now()
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime, nullable=False, default=func.now(), onupdate=func.now()
|
|
)
|
|
deleted_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
|
|
pedimento: Mapped["Pedimentos"] = relationship(
|
|
"Pedimentos", back_populates="pedimento_payments"
|
|
)
|