815cbf9d8c
- 更新 .gitignore:全面覆盖环境变量、数据库、日志、缓存、上传文件 - 移除误跟踪的 server/venv/、crm_data.db、.env 文件 - 新增 server/.env.example 模板 - 新增合同管理、利润核算、AI教练等功能模块 - 新增 Playwright e2e 测试套件 - 前后端多项功能升级和 bug 修复
90 lines
3.3 KiB
Python
90 lines
3.3 KiB
Python
"""
|
|
ERP 物流域 ORM 模型
|
|
映射: erp_shipping_records / erp_shipping_items
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
from datetime import date, datetime
|
|
|
|
from sqlalchemy import (
|
|
Boolean,
|
|
Date,
|
|
DateTime,
|
|
ForeignKey,
|
|
Numeric,
|
|
String,
|
|
Text,
|
|
func,
|
|
)
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import Base
|
|
|
|
|
|
class ErpShippingRecord(Base):
|
|
__tablename__ = "erp_shipping_records"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
|
)
|
|
shipping_no: Mapped[str] = mapped_column(String(30), unique=True, nullable=False)
|
|
order_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), ForeignKey("erp_orders.id"), nullable=False
|
|
)
|
|
carrier: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
|
tracking_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
|
status: Mapped[str] = mapped_column(String(20), nullable=False, default="transit")
|
|
ship_date: Mapped[date] = mapped_column(Date, default=date.today)
|
|
remark: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
operator_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
UUID(as_uuid=True), ForeignKey("sys_users.id"), nullable=True
|
|
)
|
|
company_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), ForeignKey("sys_companies.id"), nullable=False, index=True
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime, server_default=func.now(), onupdate=func.now()
|
|
)
|
|
is_deleted: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
|
|
# 关系
|
|
order: Mapped["ErpOrder"] = relationship("ErpOrder", lazy="selectin") # noqa: F821
|
|
operator: Mapped["SysUser | None"] = relationship("SysUser", lazy="selectin") # noqa: F821
|
|
items: Mapped[list[ErpShippingItem]] = relationship(
|
|
"ErpShippingItem", back_populates="shipping_record", lazy="selectin"
|
|
)
|
|
|
|
|
|
class ErpShippingItem(Base):
|
|
__tablename__ = "erp_shipping_items"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
|
)
|
|
shipping_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), ForeignKey("erp_shipping_records.id"), nullable=False
|
|
)
|
|
order_item_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), ForeignKey("erp_order_items.id"), nullable=False
|
|
)
|
|
sku_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), ForeignKey("erp_product_skus.id"), nullable=False
|
|
)
|
|
shipped_qty: Mapped[float] = mapped_column(Numeric(12, 2), nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime, server_default=func.now(), onupdate=func.now()
|
|
)
|
|
is_deleted: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
|
|
# 关系
|
|
shipping_record: Mapped[ErpShippingRecord] = relationship(
|
|
"ErpShippingRecord", back_populates="items"
|
|
)
|
|
order_item: Mapped["ErpOrderItem"] = relationship("ErpOrderItem", lazy="selectin") # noqa: F821
|
|
sku: Mapped["ProductSku"] = relationship("ProductSku", lazy="selectin") # noqa: F821
|