
Features include: - User management with JWT authentication and role-based access - Inventory items with SKU/barcode tracking and stock management - Categories and suppliers organization - Inventory transactions with automatic stock updates - Low stock alerts and advanced search/filtering - RESTful API with comprehensive CRUD operations - SQLite database with Alembic migrations - Auto-generated API documentation Co-Authored-By: Claude <noreply@anthropic.com>
28 lines
1.4 KiB
Python
28 lines
1.4 KiB
Python
from typing import List
|
|
from sqlalchemy.orm import Session
|
|
from app.crud.base import CRUDBase
|
|
from app.models.inventory_transaction import InventoryTransaction, TransactionType
|
|
from app.schemas.inventory_transaction import InventoryTransactionCreate
|
|
|
|
class CRUDInventoryTransaction(CRUDBase[InventoryTransaction, InventoryTransactionCreate, InventoryTransactionCreate]):
|
|
def get_by_item(self, db: Session, *, item_id: int, skip: int = 0, limit: int = 100) -> List[InventoryTransaction]:
|
|
return db.query(InventoryTransaction).filter(
|
|
InventoryTransaction.item_id == item_id
|
|
).order_by(InventoryTransaction.created_at.desc()).offset(skip).limit(limit).all()
|
|
|
|
def get_by_type(self, db: Session, *, transaction_type: TransactionType, skip: int = 0, limit: int = 100) -> List[InventoryTransaction]:
|
|
return db.query(InventoryTransaction).filter(
|
|
InventoryTransaction.transaction_type == transaction_type
|
|
).order_by(InventoryTransaction.created_at.desc()).offset(skip).limit(limit).all()
|
|
|
|
def create_with_user(self, db: Session, *, obj_in: InventoryTransactionCreate, user_id: int) -> InventoryTransaction:
|
|
db_obj = InventoryTransaction(
|
|
**obj_in.dict(),
|
|
user_id=user_id
|
|
)
|
|
db.add(db_obj)
|
|
db.commit()
|
|
db.refresh(db_obj)
|
|
return db_obj
|
|
|
|
inventory_transaction = CRUDInventoryTransaction(InventoryTransaction) |