fix - cereat org qouta stat on distribution

This commit is contained in:
2025-12-06 17:16:30 +03:30
parent 0f711afe66
commit 7486ade538
3 changed files with 14 additions and 8 deletions

View File

@@ -4,7 +4,7 @@ import jdatetime
from django.contrib.postgres.fields import ArrayField
from django.db import models
from django.db import transaction
from django.db.models import Sum
from django.db.models import Sum, QuerySet
from simple_history.models import HistoricalRecords
from apps.authentication.models import OrganizationType, Organization
@@ -546,11 +546,19 @@ class Quota(BaseModel):
quota=self,
organization=org
)
elif not stat.exists() and org.type.key != 'ADM':
stat, created = OrganizationQuotaStats.objects.get_or_create(
quota=self,
organization=org,
stat_type='distribution'
)
stat = stat.first() if isinstance(stat, QuerySet) else stat
# first quota created is none stat on attribute & broker value table
if stat.first().stat_type == 'quota':
if stat and stat.stat_type == 'quota':
return None
return stat.first() if stat.exists() else None
return stat if stat else None
def soft_delete(self):
self.trash = True