fix - custom APIExceptions for quota stats
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import APIException
|
||||
from rest_framework import serializers, status
|
||||
|
||||
from apps.livestock.web.api.v1.serializers import LiveStockTypeSerializer
|
||||
from apps.product import models as product_models
|
||||
from apps.product.exceptions import QuotaException
|
||||
from apps.product.web.api.v1.serializers import product_serializers
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@ class QuotaSerializer(serializers.ModelSerializer):
|
||||
weight = attrs['quota_weight']
|
||||
if self.instance:
|
||||
if self.instance.quota_distributed < weight:
|
||||
raise APIException("Quota weight cannot be less than distributed weight.")
|
||||
raise QuotaException(
|
||||
"وزن سهمیه نمیتواند کمتر از وزن توزیع شده باشد", # noqa
|
||||
status.HTTP_403_FORBIDDEN
|
||||
)
|
||||
return attrs
|
||||
|
||||
def to_representation(self, instance: product_models.Quota):
|
||||
|
||||
Reference in New Issue
Block a user