72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
# /opt/docker/dev/service_finder/backend/app/models/finance.py
|
|
"""
|
|
Finance modellek: Issuer (Kibocsátó) és FinancialLedger (Pénzügyi főkönyv) bővítése.
|
|
"""
|
|
|
|
import enum
|
|
import uuid
|
|
from datetime import datetime
|
|
from typing import Any, Optional
|
|
from sqlalchemy import String, DateTime, JSON, ForeignKey, Numeric, Boolean, Integer, text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.dialects.postgresql import UUID as PG_UUID, ENUM as PG_ENUM
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class IssuerType(str, enum.Enum):
|
|
"""Kibocsátó típusok (jogi forma)."""
|
|
KFT = "KFT"
|
|
EV = "EV"
|
|
BT = "BT"
|
|
ZRT = "ZRT"
|
|
OTHER = "OTHER"
|
|
|
|
|
|
class Issuer(Base):
|
|
"""
|
|
Kibocsátó (számlakibocsátó) entitás.
|
|
|
|
A rendszerben a számlákat kibocsátó jogi személyek vagy vállalkozások.
|
|
Például: KFT, EV, stb. A revenue_limit meghatározza az adóhatár összegét.
|
|
"""
|
|
__tablename__ = "issuers"
|
|
__table_args__ = {"schema": "finance"}
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
|
|
# Név és adószám
|
|
name: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
|
|
tax_id: Mapped[Optional[str]] = mapped_column(String(50), unique=True, index=True)
|
|
|
|
# Típus
|
|
type: Mapped[IssuerType] = mapped_column(
|
|
PG_ENUM(IssuerType, name="issuer_type", schema="finance"),
|
|
default=IssuerType.OTHER,
|
|
nullable=False
|
|
)
|
|
|
|
# Bevételi limit (pl. KATA határ)
|
|
revenue_limit: Mapped[float] = mapped_column(Numeric(18, 4), default=19500000.0)
|
|
current_revenue: Mapped[float] = mapped_column(Numeric(18, 4), default=0.0)
|
|
|
|
# Aktív-e
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
|
|
# API konfiguráció (pl. számlázó rendszer integráció)
|
|
api_config: Mapped[Any] = mapped_column(JSON, server_default=text("'{}'::jsonb"))
|
|
|
|
# Időbélyegek
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Issuer {self.id}: {self.name} ({self.type})>"
|
|
|
|
|
|
# Import FinancialLedger from audit module? We'll keep it separate.
|
|
# The FinancialLedger class remains in audit.py, but we add fields there.
|
|
# For completeness, we could also define it here, but to avoid duplication,
|
|
# we'll just import it if needed.
|
|
# Instead, we'll add a relationship from FinancialLedger to Issuer in audit.py. |