Automated Action 5935f302dc Create Small Business Inventory Management System with FastAPI and SQLite
- Set up project structure and FastAPI application
- Create database models with SQLAlchemy
- Implement authentication with JWT
- Add CRUD operations for products, inventory, categories
- Implement purchase order and sales functionality
- Create reporting endpoints
- Set up Alembic for database migrations
- Add comprehensive documentation in README.md
2025-05-16 08:53:15 +00:00

45 lines
1.2 KiB
Python

from typing import Optional, List
from decimal import Decimal
from pydantic import BaseModel, Field, condecimal
# Shared properties
class ProductBase(BaseModel):
name: str
description: Optional[str] = None
sku: Optional[str] = None
barcode: Optional[str] = None
unit_price: condecimal(decimal_places=2, ge=0) = Field(..., description="Selling price per unit")
cost_price: condecimal(decimal_places=2, ge=0) = Field(..., description="Cost price per unit")
category_id: Optional[int] = None
# Properties to receive on product creation
class ProductCreate(ProductBase):
pass
# Properties to receive on product update
class ProductUpdate(ProductBase):
name: Optional[str] = None
unit_price: Optional[condecimal(decimal_places=2, ge=0)] = None
cost_price: Optional[condecimal(decimal_places=2, ge=0)] = None
# Properties shared by models in DB
class ProductInDBBase(ProductBase):
id: int
class Config:
from_attributes = True
# Properties to return via API
class Product(ProductInDBBase):
pass
# Properties for product with detailed inventory information
class ProductWithInventory(Product):
total_quantity: int
available_quantity: int