document-processor/app/models/document_line_item.py

30 lines
1.6 KiB
Python

from datetime import date, datetime
from decimal import Decimal
from sqlalchemy import JSON, Date, DateTime, ForeignKey, Integer, Numeric, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.db.base import Base
class DocumentLineItem(Base):
__tablename__ = "document_line_items"
id: Mapped[int] = mapped_column(primary_key=True, index=True)
line_item_set_id: Mapped[int] = mapped_column(ForeignKey("document_line_item_sets.id"), nullable=False, index=True)
line_number: Mapped[int] = mapped_column(Integer, nullable=False)
entry_date: Mapped[date | None] = mapped_column(Date, nullable=True)
description: Mapped[str | None] = mapped_column(Text, nullable=True)
quantity: Mapped[Decimal | None] = mapped_column(Numeric(18, 4), nullable=True)
unit_price: Mapped[Decimal | None] = mapped_column(Numeric(18, 4), nullable=True)
line_total: Mapped[Decimal | None] = mapped_column(Numeric(18, 4), nullable=True)
tax_amount: Mapped[Decimal | None] = mapped_column(Numeric(18, 4), nullable=True)
category: Mapped[str | None] = mapped_column(String(100), nullable=True)
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
raw_json: Mapped[dict | None] = mapped_column(JSON, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
line_item_set: Mapped["DocumentLineItemSet"] = relationship(back_populates="items")