85 lines
1.8 KiB
Python
85 lines
1.8 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
# Shared properties
|
|
class ProductBase(BaseModel):
|
|
name: Optional[str] = None
|
|
description: Optional[str] = None
|
|
sku: Optional[str] = None
|
|
barcode: Optional[str] = None
|
|
price: Optional[float] = None
|
|
cost_price: Optional[float] = None
|
|
min_stock_level: Optional[int] = None
|
|
max_stock_level: Optional[int] = None
|
|
is_active: Optional[bool] = True
|
|
category_id: Optional[str] = None
|
|
supplier_id: Optional[str] = None
|
|
|
|
|
|
# Properties to receive via API on creation
|
|
class ProductCreate(ProductBase):
|
|
name: str
|
|
price: float
|
|
|
|
|
|
# Properties to receive via API on update
|
|
class ProductUpdate(ProductBase):
|
|
pass
|
|
|
|
|
|
# Properties for stock update
|
|
class StockUpdate(BaseModel):
|
|
quantity: int
|
|
notes: Optional[str] = None
|
|
|
|
|
|
# Properties to return via API
|
|
class ProductInDB(ProductBase):
|
|
id: str
|
|
name: str
|
|
current_stock: int
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Additional properties to return via API
|
|
class Product(ProductInDB):
|
|
pass
|
|
|
|
|
|
# Properties for product with category and supplier details
|
|
class ProductWithDetails(Product):
|
|
category: Optional["CategoryMinimal"] = None
|
|
supplier: Optional["SupplierMinimal"] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Minimal category representation for product response
|
|
class CategoryMinimal(BaseModel):
|
|
id: str
|
|
name: str
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Minimal supplier representation for product response
|
|
class SupplierMinimal(BaseModel):
|
|
id: str
|
|
name: str
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Update recursive forward references
|
|
ProductWithDetails.model_rebuild()
|