
This commit implements a comprehensive inventory management system for small businesses using FastAPI and SQLAlchemy. Features include: - Product and category management - Inventory tracking across multiple locations - Supplier management - Purchase management - Transaction tracking for inventory movements - Complete API documentation generated with BackendIM... (backend.im)
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from sqlalchemy.orm import Session
|
|
from app.models.product import Category
|
|
from app.models.inventory import Location, LocationType
|
|
|
|
def init_db(db: Session) -> None:
|
|
"""Initialize database with default data"""
|
|
|
|
# Check if we already have data
|
|
if db.query(Category).first():
|
|
return # Database already initialized
|
|
|
|
# Create default categories
|
|
default_categories = [
|
|
Category(name="General", description="General products"),
|
|
Category(name="Electronics", description="Electronic products"),
|
|
Category(name="Office Supplies", description="Office supplies and stationery"),
|
|
Category(name="Furniture", description="Furniture items"),
|
|
]
|
|
|
|
db.add_all(default_categories)
|
|
|
|
# Create default locations
|
|
default_locations = [
|
|
Location(name="Main Warehouse", type=LocationType.WAREHOUSE,
|
|
description="Main storage warehouse"),
|
|
Location(name="Store Front", type=LocationType.STORE,
|
|
description="Main store front"),
|
|
]
|
|
|
|
db.add_all(default_locations)
|
|
|
|
db.commit() |