Fix new services implementation 3

This commit is contained in:
Urtzi Alfaro
2025-08-14 16:47:34 +02:00
parent 0951547e92
commit 03737430ee
51 changed files with 657 additions and 982 deletions

View File

@@ -464,47 +464,47 @@ async def get_orders_by_supplier(
raise HTTPException(status_code=500, detail="Failed to retrieve orders by supplier")
@router.get("/ingredients/{ingredient_id}/history")
async def get_ingredient_purchase_history(
ingredient_id: UUID = Path(..., description="Ingredient ID"),
@router.get("/inventory-products/{inventory_product_id}/history")
async def get_inventory_product_purchase_history(
inventory_product_id: UUID = Path(..., description="Inventory Product ID"),
days_back: int = Query(90, ge=1, le=365, description="Number of days to look back"),
current_user: UserInfo = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""Get purchase history for a specific ingredient"""
"""Get purchase history for a specific inventory product"""
require_permissions(current_user, ["purchase_orders:read"])
try:
service = PurchaseOrderService(db)
history = await service.get_ingredient_purchase_history(
history = await service.get_inventory_product_purchase_history(
tenant_id=current_user.tenant_id,
ingredient_id=ingredient_id,
inventory_product_id=inventory_product_id,
days_back=days_back
)
return history
except Exception as e:
logger.error("Error getting ingredient purchase history", ingredient_id=str(ingredient_id), error=str(e))
raise HTTPException(status_code=500, detail="Failed to retrieve ingredient purchase history")
logger.error("Error getting inventory product purchase history", inventory_product_id=str(inventory_product_id), error=str(e))
raise HTTPException(status_code=500, detail="Failed to retrieve inventory product purchase history")
@router.get("/ingredients/top-purchased")
async def get_top_purchased_ingredients(
@router.get("/inventory-products/top-purchased")
async def get_top_purchased_inventory_products(
days_back: int = Query(30, ge=1, le=365, description="Number of days to look back"),
limit: int = Query(10, ge=1, le=50, description="Number of top ingredients to return"),
limit: int = Query(10, ge=1, le=50, description="Number of top inventory products to return"),
current_user: UserInfo = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""Get most purchased ingredients by value"""
"""Get most purchased inventory products by value"""
require_permissions(current_user, ["purchase_orders:read"])
try:
service = PurchaseOrderService(db)
ingredients = await service.get_top_purchased_ingredients(
products = await service.get_top_purchased_inventory_products(
tenant_id=current_user.tenant_id,
days_back=days_back,
limit=limit
)
return ingredients
return products
except Exception as e:
logger.error("Error getting top purchased ingredients", error=str(e))
raise HTTPException(status_code=500, detail="Failed to retrieve top purchased ingredients")
logger.error("Error getting top purchased inventory products", error=str(e))
raise HTTPException(status_code=500, detail="Failed to retrieve top purchased inventory products")