fix - cereat org qouta stat on distribution
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -9,8 +9,8 @@ from apps.product.exceptions import (
|
||||
QuotaExpiredTimeException,
|
||||
QuotaLimitByOrganizationException
|
||||
)
|
||||
from apps.product.pos.api.v1.serializers import product_serializers
|
||||
from apps.product.pos.api.v1.serializers.quota_serializers import QuotaBrokerValueSerializer, QuotaSerializer
|
||||
from apps.product.web.api.v1.serializers import product_serializers
|
||||
from apps.product.web.api.v1.serializers.quota_serializers import QuotaBrokerValueSerializer, QuotaSerializer
|
||||
|
||||
|
||||
class QuotaDistributionSerializer(serializers.ModelSerializer):
|
||||
@@ -95,11 +95,9 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
||||
""" Custom output of serializer """
|
||||
|
||||
representation = super().to_representation(instance)
|
||||
|
||||
quota = instance.quota
|
||||
assigned_org = instance.assigned_organization
|
||||
assigner_org = instance.assigner_organization
|
||||
|
||||
# get org quota stat detail
|
||||
quotas_stat_amount = instance.quota.quota_amount_by_org(assigned_org)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user