76 lines
1.6 KiB
Python
76 lines
1.6 KiB
Python
from datetime import datetime
|
|
from enum import Enum
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class MovementTypeEnum(str, Enum):
|
|
STOCK_IN = "STOCK_IN"
|
|
STOCK_OUT = "STOCK_OUT"
|
|
ADJUSTMENT = "ADJUSTMENT"
|
|
RETURN = "RETURN"
|
|
|
|
|
|
# Shared properties
|
|
class InventoryMovementBase(BaseModel):
|
|
product_id: Optional[str] = None
|
|
quantity: Optional[int] = None
|
|
type: Optional[MovementTypeEnum] = None
|
|
reference: Optional[str] = None
|
|
notes: Optional[str] = None
|
|
unit_price: Optional[float] = None
|
|
|
|
|
|
# Properties to receive via API on creation
|
|
class InventoryMovementCreate(InventoryMovementBase):
|
|
product_id: str
|
|
quantity: int
|
|
type: MovementTypeEnum
|
|
|
|
|
|
# Properties to receive via API on update
|
|
class InventoryMovementUpdate(InventoryMovementBase):
|
|
pass
|
|
|
|
|
|
# Properties to return via API
|
|
class InventoryMovementInDB(InventoryMovementBase):
|
|
id: str
|
|
product_id: str
|
|
quantity: int
|
|
type: MovementTypeEnum
|
|
created_by: Optional[str] = None
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Additional properties to return via API
|
|
class InventoryMovement(InventoryMovementInDB):
|
|
pass
|
|
|
|
|
|
# Inventory movement with product details
|
|
class InventoryMovementWithProduct(InventoryMovement):
|
|
product: "ProductMinimal"
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Minimal product representation for movement response
|
|
class ProductMinimal(BaseModel):
|
|
id: str
|
|
name: str
|
|
sku: Optional[str] = None
|
|
current_stock: int
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Update recursive forward references
|
|
InventoryMovementWithProduct.model_rebuild()
|