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)