Add subcription level filtering
This commit is contained in:
@@ -7,6 +7,7 @@ import structlog
|
||||
from typing import Dict, Any, Optional
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from fastapi import HTTPException, status
|
||||
import httpx
|
||||
|
||||
from app.repositories import SubscriptionRepository, TenantRepository, TenantMemberRepository
|
||||
from app.models.tenants import Subscription, Tenant, TenantMember
|
||||
@@ -287,10 +288,12 @@ class SubscriptionLimitService:
|
||||
# Get current usage
|
||||
members = await self.member_repo.get_tenant_members(tenant_id, active_only=True)
|
||||
current_users = len(members)
|
||||
|
||||
# TODO: Implement actual location and product counts
|
||||
|
||||
# Get actual ingredient/product count from inventory service
|
||||
current_products = await self._get_ingredient_count(tenant_id)
|
||||
|
||||
# TODO: Implement actual location count
|
||||
current_locations = 1
|
||||
current_products = 0
|
||||
|
||||
return {
|
||||
"plan": subscription.plan,
|
||||
@@ -327,6 +330,32 @@ class SubscriptionLimitService:
|
||||
error=str(e))
|
||||
return {"error": "Failed to get usage summary"}
|
||||
|
||||
async def _get_ingredient_count(self, tenant_id: str) -> int:
|
||||
"""Get ingredient count from inventory service using shared client"""
|
||||
try:
|
||||
from app.core.config import settings
|
||||
from shared.clients.inventory_client import create_inventory_client
|
||||
|
||||
# Use the shared inventory client with proper authentication
|
||||
inventory_client = create_inventory_client(settings)
|
||||
count = await inventory_client.count_ingredients(tenant_id)
|
||||
|
||||
logger.info(
|
||||
"Retrieved ingredient count via inventory client",
|
||||
tenant_id=tenant_id,
|
||||
count=count
|
||||
)
|
||||
return count
|
||||
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"Error getting ingredient count via inventory client",
|
||||
tenant_id=tenant_id,
|
||||
error=str(e)
|
||||
)
|
||||
# Return 0 as fallback to avoid breaking subscription display
|
||||
return 0
|
||||
|
||||
|
||||
# Legacy alias for backward compatibility
|
||||
SubscriptionService = SubscriptionLimitService
|
||||
Reference in New Issue
Block a user