fix fix fi x fix
This commit is contained in:
@@ -1896,18 +1896,27 @@ class AutomationService:
|
||||
"""
|
||||
Get total credits used by this run so far.
|
||||
Uses CreditUsageLog (same source as /account/usage/credits endpoint) for accuracy.
|
||||
Filters by site to only count credits used by this specific automation run.
|
||||
"""
|
||||
if not self.run:
|
||||
return 0
|
||||
|
||||
# FIXED: Use CreditUsageLog instead of counting AITaskLog records
|
||||
# This matches the source of truth used by /account/usage/credits endpoint
|
||||
# Use CreditUsageLog - the source of truth for credit usage
|
||||
# Filter by site to get only credits used by this automation run
|
||||
from igny8_core.business.billing.models import CreditUsageLog
|
||||
from django.db.models import Sum
|
||||
|
||||
filters = {
|
||||
'account': self.account,
|
||||
'created_at__gte': self.run.started_at
|
||||
}
|
||||
|
||||
# Filter by site if available for more accurate per-run counting
|
||||
if self.site:
|
||||
filters['site'] = self.site
|
||||
|
||||
total = CreditUsageLog.objects.filter(
|
||||
account=self.account,
|
||||
created_at__gte=self.run.started_at
|
||||
**filters
|
||||
).aggregate(total=Sum('credits_used'))['total'] or 0
|
||||
|
||||
return total
|
||||
|
||||
Reference in New Issue
Block a user