Improve the frontend and fix TODOs
This commit is contained in:
@@ -7,7 +7,7 @@ from typing import List, Optional, Dict, Any, Tuple
|
||||
from uuid import UUID
|
||||
from datetime import datetime, timedelta
|
||||
from decimal import Decimal
|
||||
from sqlalchemy import select, func, and_, or_, desc, asc, update
|
||||
from sqlalchemy import select, func, and_, or_, desc, asc, update, exists
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
import structlog
|
||||
|
||||
@@ -400,12 +400,33 @@ class StockRepository(BaseRepository[Stock, StockCreate, StockUpdate], BatchCoun
|
||||
)
|
||||
expiring_count = expiring_result.scalar() or 0
|
||||
|
||||
# Count out of stock items (ingredients with no available stock)
|
||||
out_of_stock_result = await self.session.execute(
|
||||
select(func.count(Ingredient.id)).where(
|
||||
and_(
|
||||
Ingredient.tenant_id == tenant_id,
|
||||
~exists(
|
||||
select(1).where(
|
||||
and_(
|
||||
Stock.ingredient_id == Ingredient.id,
|
||||
Stock.tenant_id == tenant_id,
|
||||
Stock.is_available == True,
|
||||
Stock.available_quantity > 0
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
out_of_stock_count = out_of_stock_result.scalar() or 0
|
||||
|
||||
return {
|
||||
'total_stock_items': basic_summary.total_stock_items or 0,
|
||||
'total_stock_value': float(basic_summary.total_stock_value) if basic_summary.total_stock_value else 0.0,
|
||||
'unique_ingredients': basic_summary.unique_ingredients or 0,
|
||||
'expired_items': expired_count,
|
||||
'expiring_soon_items': expiring_count
|
||||
'expiring_soon_items': expiring_count,
|
||||
'out_of_stock_count': out_of_stock_count
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user