Add POI feature and imporve the overall backend implementation
This commit is contained in:
@@ -332,7 +332,10 @@ class IngredientRepository(BaseRepository[Ingredient, IngredientCreate, Ingredie
|
||||
'ingredient': ingredient,
|
||||
'current_stock': float(current_stock) if current_stock else 0.0,
|
||||
'threshold': ingredient.low_stock_threshold,
|
||||
'needs_reorder': current_stock <= ingredient.reorder_point if current_stock else True
|
||||
'needs_reorder': (
|
||||
current_stock <= ingredient.reorder_point
|
||||
if current_stock and ingredient.reorder_point is not None else True
|
||||
)
|
||||
})
|
||||
|
||||
return results
|
||||
|
||||
@@ -98,6 +98,28 @@ class StockRepository(BaseRepository[Stock, StockCreate, StockUpdate], BatchCoun
|
||||
logger.error("Failed to get stock by ingredient", error=str(e), ingredient_id=ingredient_id)
|
||||
raise
|
||||
|
||||
async def get_stock_by_product(
|
||||
self,
|
||||
tenant_id: UUID,
|
||||
inventory_product_id: UUID,
|
||||
include_unavailable: bool = False
|
||||
) -> List[Stock]:
|
||||
"""
|
||||
Get all stock entries for a specific product.
|
||||
|
||||
Note: inventory_product_id and ingredient_id refer to the same entity.
|
||||
The 'ingredients' table is used as a unified catalog for both raw ingredients
|
||||
and finished products, distinguished by the product_type field.
|
||||
|
||||
This method is an alias for get_stock_by_ingredient for clarity when called
|
||||
from contexts that use 'product' terminology (e.g., procurement service).
|
||||
"""
|
||||
return await self.get_stock_by_ingredient(
|
||||
tenant_id=tenant_id,
|
||||
ingredient_id=inventory_product_id,
|
||||
include_unavailable=include_unavailable
|
||||
)
|
||||
|
||||
async def get_total_stock_by_ingredient(self, tenant_id: UUID, ingredient_id: UUID) -> Dict[str, float]:
|
||||
"""Get total stock quantities for an ingredient"""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user