
- Created FastAPI application with SQLite database - Implemented models for inventory items, categories, suppliers, and transactions - Added authentication system with JWT tokens - Implemented CRUD operations for all models - Set up Alembic for database migrations - Added comprehensive API documentation - Configured Ruff for code linting
71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field, validator
|
|
|
|
from app.models.transaction import TransactionType
|
|
|
|
|
|
class TransactionBase(BaseModel):
|
|
"""
|
|
Base transaction schema with common attributes.
|
|
"""
|
|
item_id: int = Field(..., description="ID of the item")
|
|
quantity: int = Field(..., description="Transaction quantity", gt=0)
|
|
transaction_type: TransactionType = Field(..., description="Type of transaction")
|
|
unit_price: float = Field(..., description="Unit price", gt=0)
|
|
reference: Optional[str] = Field(None, description="Reference number or order ID")
|
|
notes: Optional[str] = Field(None, description="Additional notes")
|
|
|
|
|
|
class TransactionCreate(TransactionBase):
|
|
"""
|
|
Schema for transaction creation.
|
|
"""
|
|
|
|
@validator('transaction_type')
|
|
def validate_transaction_type(cls, v):
|
|
if v not in [TransactionType.STOCK_IN, TransactionType.STOCK_OUT]:
|
|
raise ValueError('Transaction type must be either stock_in or stock_out')
|
|
return v
|
|
|
|
|
|
class TransactionUpdate(BaseModel):
|
|
"""
|
|
Schema for updating transaction information.
|
|
"""
|
|
quantity: Optional[int] = Field(None, description="Transaction quantity", gt=0)
|
|
unit_price: Optional[float] = Field(None, description="Unit price", gt=0)
|
|
reference: Optional[str] = Field(None, description="Reference number or order ID")
|
|
notes: Optional[str] = Field(None, description="Additional notes")
|
|
|
|
|
|
class TransactionInDBBase(TransactionBase):
|
|
"""
|
|
Base schema for transactions from the database.
|
|
"""
|
|
id: int = Field(..., description="Transaction ID")
|
|
total_price: float = Field(..., description="Total transaction price")
|
|
timestamp: datetime = Field(..., description="Transaction timestamp")
|
|
user_id: int = Field(..., description="ID of the user who performed the transaction")
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class Transaction(TransactionInDBBase):
|
|
"""
|
|
Schema for transaction information returned to clients.
|
|
"""
|
|
pass
|
|
|
|
|
|
class TransactionWithDetails(TransactionInDBBase):
|
|
"""
|
|
Schema for transaction with related entities.
|
|
"""
|
|
from app.schemas.item import Item
|
|
from app.schemas.user import User
|
|
|
|
item: Item = Field(..., description="Transaction item")
|
|
user: User = Field(..., description="User who performed the transaction") |