2026-09-22 16:13:45 +08:00
|
|
|
from pydantic import BaseModel, ConfigDict
|
2026-05-11 14:46:20 +08:00
|
|
|
from typing import Optional, List
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
from decimal import Decimal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductCreate(BaseModel):
|
|
|
|
|
sku: str
|
|
|
|
|
name: str
|
|
|
|
|
description: Optional[str] = None
|
|
|
|
|
category: Optional[str] = None
|
|
|
|
|
unit: str = "件"
|
|
|
|
|
item_type: str = "finished"
|
|
|
|
|
cost_price: Decimal = Decimal("0")
|
|
|
|
|
sale_price: Decimal = Decimal("0")
|
|
|
|
|
min_stock: int = 0
|
|
|
|
|
max_stock: int = 1000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductResponse(BaseModel):
|
|
|
|
|
id: int
|
|
|
|
|
sku: str
|
|
|
|
|
name: str
|
|
|
|
|
description: Optional[str]
|
|
|
|
|
category: Optional[str]
|
|
|
|
|
unit: str
|
|
|
|
|
item_type: str
|
|
|
|
|
cost_price: Decimal
|
|
|
|
|
sale_price: Decimal
|
|
|
|
|
min_stock: int
|
|
|
|
|
max_stock: int
|
|
|
|
|
material_cost: Decimal = Decimal("0")
|
|
|
|
|
is_active: bool
|
|
|
|
|
created_at: datetime
|
|
|
|
|
|
2026-09-22 16:13:45 +08:00
|
|
|
model_config = ConfigDict(from_attributes=True)
|
2026-05-11 14:46:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductMaterialItemUpdate(BaseModel):
|
|
|
|
|
material_id: int
|
|
|
|
|
quantity: Decimal
|
|
|
|
|
loss_rate: Decimal = Decimal("0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductBOMUpdate(BaseModel):
|
|
|
|
|
items: List[ProductMaterialItemUpdate]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductMaterialItemResponse(BaseModel):
|
|
|
|
|
material_id: int
|
|
|
|
|
material_sku: str
|
|
|
|
|
material_name: str
|
|
|
|
|
quantity: Decimal
|
|
|
|
|
unit_cost: Decimal
|
|
|
|
|
line_cost: Decimal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductBOMResponse(BaseModel):
|
|
|
|
|
product_id: int
|
|
|
|
|
product_name: str
|
|
|
|
|
total_material_cost: Decimal
|
|
|
|
|
items: List[ProductMaterialItemResponse]
|