50 lines
2.8 KiB
Python
50 lines
2.8 KiB
Python
from src.models.base import Base, UUIDPrimaryMixin
|
|
import uuid
|
|
from decimal import Decimal
|
|
from sqlalchemy import ForeignKey, String, Boolean, Enum as SAEnum, BigInteger, Numeric, Date, SmallInteger
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from src.schemas.enums import StatementType, FslRowKind
|
|
from datetime import date
|
|
|
|
|
|
class FinancialStatementMeta(Base, UUIDPrimaryMixin):
|
|
__tablename__ = "financial_statement_meta"
|
|
|
|
stored_file_id: Mapped[uuid.UUID] = mapped_column(ForeignKey('stored_file.id'), nullable=False)
|
|
statement_type: Mapped[StatementType] = mapped_column(SAEnum(StatementType, native_enum=False, create_constraint=False))
|
|
inn: Mapped[str] = mapped_column(String)
|
|
inn_verified: Mapped[bool] = mapped_column(Boolean)
|
|
report_date: Mapped[date] = mapped_column(Date, nullable=True)
|
|
report_date_verified: Mapped[bool] = mapped_column(Boolean)
|
|
units: Mapped[str] = mapped_column(String)
|
|
units_verified: Mapped[bool] = mapped_column(Boolean)
|
|
|
|
lines: Mapped[list["FinancialStatementLine"]] = relationship("FinancialStatementLine", back_populates="meta", lazy="raise")
|
|
|
|
class FinancialStatementLine(Base, UUIDPrimaryMixin):
|
|
__tablename__ = "financial_statement_line"
|
|
|
|
recognition_job_id: Mapped[uuid.UUID] = mapped_column(ForeignKey('recognition_job.id'), nullable=False)
|
|
# stored_file_id: Mapped[uuid.UUID] = mapped_column(ForeignKey('stored_file.id'), nullable=False)
|
|
meta_id = mapped_column(ForeignKey('financial_statement_meta.id'))
|
|
legal_entity_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("legal_entity.id"))
|
|
line_code: Mapped[str] = mapped_column(String)
|
|
line_code_recognized: Mapped[bool] = mapped_column(Boolean)
|
|
line_name: Mapped[str] = mapped_column(String)
|
|
line_name_recognized: Mapped[bool] = mapped_column(Boolean)
|
|
row_kind: Mapped[FslRowKind] = mapped_column(SAEnum(FslRowKind, native_enum=False, create_constraint=False))
|
|
ordinal: Mapped[int] = mapped_column(BigInteger)
|
|
|
|
meta: Mapped["FinancialStatementMeta"] = relationship("FinancialStatementMeta", back_populates="lines")
|
|
values: Mapped[list["FinancialStatementValue"]] = relationship("FinancialStatementValue", back_populates="line", lazy="raise")
|
|
|
|
class FinancialStatementValue(Base, UUIDPrimaryMixin):
|
|
__tablename__ = "financial_statement_value"
|
|
|
|
line_id: Mapped[uuid.UUID] = mapped_column(ForeignKey('financial_statement_line.id'), nullable=False)
|
|
amount: Mapped[Decimal] = mapped_column(Numeric, nullable=True)
|
|
string_value: Mapped[str] = mapped_column(String, nullable=True)
|
|
column_index: Mapped[int] = mapped_column(SmallInteger, nullable=False)
|
|
is_recognized: Mapped[bool] = mapped_column(Boolean)
|
|
|
|
line: Mapped["FinancialStatementLine"] = relationship("FinancialStatementLine", back_populates="values") |