fix - custom APIExceptions for quota stats

This commit is contained in:
2025-11-18 09:11:35 +03:30
parent d8f6eaf243
commit 4e5319b625
3 changed files with 67 additions and 11 deletions

View File

@@ -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):