diff --git a/apps/authentication/api/v1/serializers/serializer.py b/apps/authentication/api/v1/serializers/serializer.py index 4091e24..21c5adb 100644 --- a/apps/authentication/api/v1/serializers/serializer.py +++ b/apps/authentication/api/v1/serializers/serializer.py @@ -192,7 +192,8 @@ class OrganizationSerializer(serializers.ModelSerializer): 'city', 'parent_organization', 'national_unique_id', - 'company_code' + 'company_code', + 'field_of_activity' ] extra_kwargs = {} diff --git a/apps/product/exceptions.py b/apps/product/exceptions.py index a4fb90f..61e35ce 100644 --- a/apps/product/exceptions.py +++ b/apps/product/exceptions.py @@ -5,6 +5,6 @@ from rest_framework import status class QuotaWeightException(APIException): """ if quota distributions weight is more """ - status_code = status.HTTP_401_UNAUTHORIZED - default_detail = '' - default_code = 'unauthorized' + status_code = status.HTTP_400_BAD_REQUEST + default_detail = "مقدار وارد شده باعث می‌شود مجموع سهمیه‌ها از مقدار کل سهمیه بیشتر شود." # noqa + default_code = 'error' diff --git a/apps/product/web/api/v1/quota_distribution_serializers.py b/apps/product/web/api/v1/quota_distribution_serializers.py index a9a7a79..29596e8 100644 --- a/apps/product/web/api/v1/quota_distribution_serializers.py +++ b/apps/product/web/api/v1/quota_distribution_serializers.py @@ -2,7 +2,7 @@ from rest_framework import serializers from apps.product import models as product_models from apps.product.web.api.v1.product_serializers import QuotaSerializer from django.db import models -from rest_framework.exceptions import APIException +from apps.product.exceptions import QuotaWeightException from rest_framework import status @@ -20,22 +20,18 @@ class QuotaDistributionSerializer(serializers.ModelSerializer): """ to validate if distribution weight more than quota weight raise exception """ - quota = data['quota'] + quota = product_models.Quota.objects.get(id=data['quota']) amount = data['weight'] instance_id = self.instance.id if self.instance else None total = product_models.QuotaDistribution.objects.filter( - quota_id=quota + quota=quota ).exclude(id=instance_id).aggregate( total=models.Sum('weight') )['total'] or 0 print(total) if total + amount > self.instance.weight: - raise APIException( - "مقدار وارد شده باعث می‌شود مجموع سهمیه‌ها از مقدار کل سهمیه بیشتر شود.", # noqa - status.HTTP_400_BAD_REQUEST, - - ) + raise QuotaWeightException() return data