Automated Action 1d312e5ff6 Implement Small Business Inventory Management System
- 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
2025-06-06 20:27:41 +00:00

69 lines
1.8 KiB
Python

from typing import List, Optional
from sqlalchemy.orm import Session
from app.crud.base import CRUDBase
from app.models.item import Item
from app.schemas.item import ItemCreate, ItemUpdate
class CRUDItem(CRUDBase[Item, ItemCreate, ItemUpdate]):
"""
CRUD operations for Item model.
"""
def get_by_sku(self, db: Session, *, sku: str) -> Optional[Item]:
"""
Get an item by SKU.
"""
return db.query(Item).filter(Item.sku == sku).first()
def get_by_barcode(self, db: Session, *, barcode: str) -> Optional[Item]:
"""
Get an item by barcode.
"""
return db.query(Item).filter(Item.barcode == barcode).first()
def get_by_category(
self, db: Session, *, category_id: int, skip: int = 0, limit: int = 100
) -> List[Item]:
"""
Get items by category.
"""
return (
db.query(Item)
.filter(Item.category_id == category_id)
.offset(skip)
.limit(limit)
.all()
)
def get_by_supplier(
self, db: Session, *, supplier_id: int, skip: int = 0, limit: int = 100
) -> List[Item]:
"""
Get items by supplier.
"""
return (
db.query(Item)
.filter(Item.supplier_id == supplier_id)
.offset(skip)
.limit(limit)
.all()
)
def get_low_stock(
self, db: Session, *, skip: int = 0, limit: int = 100
) -> List[Item]:
"""
Get items with stock quantity below reorder level.
"""
return (
db.query(Item)
.filter(Item.quantity <= Item.reorder_level)
.offset(skip)
.limit(limit)
.all()
)
item = CRUDItem(Item)