master plan implemenattion
This commit is contained in:
@@ -1643,14 +1643,22 @@ class AutomationService:
|
||||
raise
|
||||
|
||||
def _get_credits_used(self) -> int:
|
||||
"""Get total credits used by this run so far"""
|
||||
"""
|
||||
Get total credits used by this run so far.
|
||||
Uses CreditUsageLog (same source as /account/usage/credits endpoint) for accuracy.
|
||||
"""
|
||||
if not self.run:
|
||||
return 0
|
||||
|
||||
total = AITaskLog.objects.filter(
|
||||
# FIXED: Use CreditUsageLog instead of counting AITaskLog records
|
||||
# This matches the source of truth used by /account/usage/credits endpoint
|
||||
from igny8_core.business.billing.models import CreditUsageLog
|
||||
from django.db.models import Sum
|
||||
|
||||
total = CreditUsageLog.objects.filter(
|
||||
account=self.account,
|
||||
created_at__gte=self.run.started_at
|
||||
).aggregate(total=Count('id'))['total'] or 0
|
||||
).aggregate(total=Sum('credits_used'))['total'] or 0
|
||||
|
||||
return total
|
||||
|
||||
|
||||
Reference in New Issue
Block a user