feat: add accessory models and box_item item_type column
Add FinishedGoodsAccessory and AccessoryType ORM models for the accessory module. Add item_type column to FinishedGoodsBoxItem to distinguish between products and accessories in boxing records. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
44
app/models/accessory.py
Normal file
44
app/models/accessory.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# app/models/accessory.py
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import BigInteger, DateTime, Index, Integer, String, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
SCHEMA = "CargoTrace"
|
||||
|
||||
|
||||
class FinishedGoodsAccessory(Base):
|
||||
__tablename__ = "finished_goods_accessory"
|
||||
__table_args__ = (
|
||||
Index("idx_fga_paichan_no", "paichan_no"),
|
||||
Index("idx_fga_zongpai_no", "zongpai_no"),
|
||||
Index("idx_fga_location_code", "location_code"),
|
||||
{"schema": SCHEMA},
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
|
||||
paichan_no: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
zongpai_no: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
accessory_type: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
quantity: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
location_code: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime,
|
||||
nullable=False,
|
||||
default=func.current_timestamp(),
|
||||
server_default=func.current_timestamp(),
|
||||
)
|
||||
|
||||
|
||||
class AccessoryType(Base):
|
||||
__tablename__ = "accessory_type"
|
||||
__table_args__ = (
|
||||
Index("uk_accessory_type_name", "name", unique=True),
|
||||
{"schema": SCHEMA},
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
|
||||
name: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
@@ -58,6 +58,9 @@ class FinishedGoodsBoxItem(Base):
|
||||
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)
|
||||
item_type: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default="product", server_default="product"
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime,
|
||||
nullable=False,
|
||||
|
||||
Reference in New Issue
Block a user