161 lines
4.6 KiB
Python
161 lines
4.6 KiB
Python
"""Pydantic schemas - 价格清单管理"""
|
|
from pydantic import BaseModel, Field
|
|
from typing import Optional, List
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
|
|
|
|
class PriceListItemBase(BaseModel):
|
|
"""价格清单项基础字段"""
|
|
product_id: str = Field(..., description="商品ID")
|
|
unit_id: str = Field(..., description="单位ID")
|
|
price: Decimal = Field(..., description="单价")
|
|
|
|
|
|
class PriceListItemCreate(PriceListItemBase):
|
|
"""创建价格清单项请求"""
|
|
pass
|
|
|
|
|
|
class PriceListItemUpdate(BaseModel):
|
|
"""更新价格清单项请求"""
|
|
unit_id: Optional[str] = None
|
|
price: Optional[Decimal] = None
|
|
|
|
|
|
class PriceListItemResponse(PriceListItemBase):
|
|
"""价格清单项响应"""
|
|
id: str
|
|
price_list_id: str
|
|
is_del: int
|
|
create_at: Optional[datetime] = None
|
|
# 关联信息
|
|
product_name: Optional[str] = None
|
|
category_name: Optional[str] = None
|
|
unit_name: Optional[str] = None
|
|
image_url: Optional[str] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class PriceListBase(BaseModel):
|
|
"""价格清单基础字段"""
|
|
region_id: str = Field(..., description="区域ID")
|
|
supplier_id: str = Field(..., description="供应商ID")
|
|
|
|
|
|
class PriceListCreate(PriceListBase):
|
|
"""创建价格清单请求"""
|
|
effective_time: Optional[datetime] = Field(None, description="生效时间")
|
|
effective_type: str = Field("immediate", description="生效方式: immediate-立即生效/scheduled-定时生效")
|
|
items: List[PriceListItemCreate] = Field(default_factory=list, description="价格项列表")
|
|
remark: Optional[str] = Field(None, max_length=500, description="备注")
|
|
|
|
|
|
class PriceListUpdate(BaseModel):
|
|
"""更新价格清单请求"""
|
|
effective_time: Optional[datetime] = None
|
|
items: Optional[List[PriceListItemCreate]] = None
|
|
remark: Optional[str] = None
|
|
|
|
|
|
class PriceListResponse(BaseModel):
|
|
"""价格清单响应"""
|
|
id: str
|
|
region_id: str
|
|
supplier_id: str
|
|
version: int
|
|
status: str
|
|
effective_time: Optional[datetime] = None
|
|
published_by: Optional[str] = None
|
|
published_time: Optional[datetime] = None
|
|
remark: Optional[str] = None
|
|
is_del: int
|
|
create_at: Optional[datetime] = None
|
|
create_by: Optional[str] = None
|
|
create_name: Optional[str] = None
|
|
update_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class PriceListDetailResponse(PriceListResponse):
|
|
"""价格清单详情响应(包含价格项)"""
|
|
items: List[PriceListItemResponse] = []
|
|
# 关联信息
|
|
region_name: Optional[str] = None
|
|
supplier_name: Optional[str] = None
|
|
published_by_name: Optional[str] = None
|
|
|
|
|
|
class PriceListListResponse(BaseModel):
|
|
"""价格清单列表响应"""
|
|
items: List[PriceListResponse]
|
|
total: int
|
|
page: int
|
|
pageSize: int
|
|
totalPages: int
|
|
|
|
|
|
class PriceListPublishRequest(BaseModel):
|
|
"""发布价格清单请求"""
|
|
effective_type: str = Field("immediate", description="生效方式: immediate-立即生效/scheduled-定时生效")
|
|
effective_time: Optional[datetime] = Field(None, description="定时生效时间")
|
|
remark: Optional[str] = Field(None, max_length=500, description="备注")
|
|
|
|
|
|
class PriceListInvalidateRequest(BaseModel):
|
|
"""使价格清单失效请求"""
|
|
remark: Optional[str] = Field(None, max_length=500, description="失效原因备注")
|
|
|
|
|
|
class PriceListStatusResponse(BaseModel):
|
|
"""价格清单状态更新响应"""
|
|
id: str
|
|
status: str
|
|
message: str = "操作成功"
|
|
|
|
|
|
class ProductPriceResponse(BaseModel):
|
|
"""商品价格响应"""
|
|
product_id: str
|
|
product_name: str
|
|
category_name: Optional[str] = None
|
|
unit_id: str
|
|
unit_name: Optional[str] = None
|
|
price: Decimal
|
|
price_list_id: str
|
|
price_list_version: int
|
|
|
|
|
|
class ProductPriceHistoryItem(BaseModel):
|
|
"""商品价格历史项"""
|
|
price: Decimal
|
|
unit_id: str
|
|
unit_name: Optional[str] = None
|
|
price_list_id: str
|
|
version: int
|
|
published_time: datetime
|
|
status: str
|
|
|
|
|
|
class ProductPriceHistoryResponse(BaseModel):
|
|
"""商品价格历史响应"""
|
|
product_id: str
|
|
product_name: str
|
|
history: List[ProductPriceHistoryItem]
|
|
total: int
|
|
page: int
|
|
pageSize: int
|
|
|
|
|
|
class PriceListGenerateRequest(BaseModel):
|
|
"""从报价单生成价格清单请求"""
|
|
quotation_id: str = Field(..., description="报价单ID")
|
|
region_id: str = Field(..., description="区域ID")
|
|
effective_type: str = Field("immediate", description="生效方式")
|
|
effective_time: Optional[datetime] = None
|
|
remark: Optional[str] = Field(None, max_length=500, description="备注")
|