diff --git a/app/models/__init__.py b/app/models/__init__.py new file mode 100644 index 0000000..da315dc --- /dev/null +++ b/app/models/__init__.py @@ -0,0 +1,11 @@ +from app.models.finished_goods import ( + FinishedGoodsBox, + FinishedGoodsBoxItem, + FinishedGoodsLocation, +) + +__all__ = [ + "FinishedGoodsLocation", + "FinishedGoodsBox", + "FinishedGoodsBoxItem", +] diff --git a/app/models/finished_goods.py b/app/models/finished_goods.py new file mode 100644 index 0000000..01edf05 --- /dev/null +++ b/app/models/finished_goods.py @@ -0,0 +1,57 @@ +from datetime import datetime + +from sqlalchemy import BigInteger, DateTime, Index, Numeric, String, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.core.database import Base + +SCHEMA = "CargoTrace" + + +class FinishedGoodsLocation(Base): + __tablename__ = "finished_goods_location" + __table_args__ = ( + Index("uk_zongpai_no", "zongpai_no", unique=True), + Index("idx_fgl_location_code", "location_code"), + {"schema": SCHEMA}, + ) + + id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) + zongpai_no: Mapped[str] = mapped_column(String(64), nullable=False) + location_code: Mapped[str] = mapped_column(String(64), nullable=False) + created_at: Mapped[datetime] = mapped_column( + DateTime, nullable=False, server_default=func.getdate() + ) + + +class FinishedGoodsBox(Base): + __tablename__ = "finished_goods_box" + __table_args__ = ( + Index("uk_paichan_box", "paichan_no", "box_no", unique=True), + Index("idx_fgb_paichan_no", "paichan_no"), + {"schema": SCHEMA}, + ) + + id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) + paichan_no: Mapped[str] = mapped_column(String(64), nullable=False) + box_no: Mapped[int] = mapped_column(nullable=False) + created_at: Mapped[datetime] = mapped_column( + DateTime, nullable=False, server_default=func.getdate() + ) + + +class FinishedGoodsBoxItem(Base): + __tablename__ = "finished_goods_box_item" + __table_args__ = ( + Index("idx_fgbi_box_id", "box_id"), + Index("idx_fgbi_zongpai_no", "zongpai_no"), + {"schema": SCHEMA}, + ) + + id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) + box_id: Mapped[int] = mapped_column(BigInteger, nullable=False) + zongpai_no: Mapped[str] = mapped_column(String(64), nullable=False) + quantity: Mapped[float | None] = mapped_column(Numeric(18, 3), nullable=True) + created_at: Mapped[datetime] = mapped_column( + DateTime, nullable=False, server_default=func.getdate() + )