fix - cereat org qouta stat on distribution
This commit is contained in:
@@ -7,7 +7,7 @@ ENV_NAME=DEV
|
|||||||
# Database secrets
|
# Database secrets
|
||||||
DB_HOST=31.7.78.133
|
DB_HOST=31.7.78.133
|
||||||
DB_PORT=14352
|
DB_PORT=14352
|
||||||
DB_NAME=Development
|
DB_NAME=Production
|
||||||
DB_USERNAME=postgres
|
DB_USERNAME=postgres
|
||||||
DB_PASSWORD=pfLIVXupbDetvFMt2gUvxLXUL9b4HIOHaPcKXsBEZ1i8zl0iLUjmhUfXlGfJKcTV
|
DB_PASSWORD=pfLIVXupbDetvFMt2gUvxLXUL9b4HIOHaPcKXsBEZ1i8zl0iLUjmhUfXlGfJKcTV
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import jdatetime
|
|||||||
from django.contrib.postgres.fields import ArrayField
|
from django.contrib.postgres.fields import ArrayField
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db import transaction
|
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 simple_history.models import HistoricalRecords
|
||||||
|
|
||||||
from apps.authentication.models import OrganizationType, Organization
|
from apps.authentication.models import OrganizationType, Organization
|
||||||
@@ -546,11 +546,19 @@ class Quota(BaseModel):
|
|||||||
quota=self,
|
quota=self,
|
||||||
organization=org
|
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
|
# 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 None
|
||||||
return stat.first() if stat.exists() else None
|
return stat if stat else None
|
||||||
|
|
||||||
def soft_delete(self):
|
def soft_delete(self):
|
||||||
self.trash = True
|
self.trash = True
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ from apps.product.exceptions import (
|
|||||||
QuotaExpiredTimeException,
|
QuotaExpiredTimeException,
|
||||||
QuotaLimitByOrganizationException
|
QuotaLimitByOrganizationException
|
||||||
)
|
)
|
||||||
from apps.product.pos.api.v1.serializers import product_serializers
|
from apps.product.web.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.quota_serializers import QuotaBrokerValueSerializer, QuotaSerializer
|
||||||
|
|
||||||
|
|
||||||
class QuotaDistributionSerializer(serializers.ModelSerializer):
|
class QuotaDistributionSerializer(serializers.ModelSerializer):
|
||||||
@@ -95,11 +95,9 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
|||||||
""" Custom output of serializer """
|
""" Custom output of serializer """
|
||||||
|
|
||||||
representation = super().to_representation(instance)
|
representation = super().to_representation(instance)
|
||||||
|
|
||||||
quota = instance.quota
|
quota = instance.quota
|
||||||
assigned_org = instance.assigned_organization
|
assigned_org = instance.assigned_organization
|
||||||
assigner_org = instance.assigner_organization
|
assigner_org = instance.assigner_organization
|
||||||
|
|
||||||
# get org quota stat detail
|
# get org quota stat detail
|
||||||
quotas_stat_amount = instance.quota.quota_amount_by_org(assigned_org)
|
quotas_stat_amount = instance.quota.quota_amount_by_org(assigned_org)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user