Fix credit system: Add developer/system account bypass for credit checks

- CreditService.check_credits() now bypasses for:
  1. System accounts (aws-admin, default-account, default)
  2. Developer/admin users (if user provided)
  3. Accounts with developer users (fallback for Celery tasks)
- Updated check_credits_legacy() with same bypass logic
- AIEngine credit check now uses updated CreditService
- Fixes 52 console errors caused by credit checks blocking developers
- Developers can now use AI functions without credit restrictions
This commit is contained in:
IGNY8 VPS (Salman)
2025-11-16 19:40:44 +00:00
parent 8171014a7e
commit 066b81dd2a
2 changed files with 54 additions and 4 deletions

View File

@@ -193,6 +193,7 @@ class AIEngine:
self.tracker.update("PREP", 25, prep_message, meta=self.step_tracker.get_meta())
# Phase 2.5: CREDIT CHECK - Check credits before AI call (25%)
# Bypass for system accounts and developers (handled in CreditService)
if self.account:
try:
from igny8_core.modules.billing.services import CreditService
@@ -204,8 +205,9 @@ class AIEngine:
# Calculate estimated cost
estimated_amount = self._get_estimated_amount(function_name, data, payload)
# Check credits BEFORE AI call
CreditService.check_credits(self.account, operation_type, estimated_amount)
# Check credits BEFORE AI call (CreditService handles developer/system account bypass)
# Note: user=None for Celery tasks, but CreditService checks account.is_system_account() and developer users
CreditService.check_credits(self.account, operation_type, estimated_amount, user=None)
logger.info(f"[AIEngine] Credit check passed: {operation_type}, estimated amount: {estimated_amount}")
except InsufficientCreditsError as e: