add - import validator for organization quota stats

This commit is contained in:
2025-11-17 16:46:59 +03:30
parent 7ffbacc331
commit d8f6eaf243
5 changed files with 91 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
from rest_framework import serializers
from rest_framework.exceptions import APIException
from apps.livestock.web.api.v1.serializers import LiveStockTypeSerializer
from apps.product import models as product_models
@@ -10,6 +11,13 @@ class QuotaSerializer(serializers.ModelSerializer):
model = product_models.Quota
fields = '__all__'
def validate(self, attrs):
weight = attrs['quota_weight']
if self.instance:
if self.instance.quota_distributed < weight:
raise APIException("Quota weight cannot be less than distributed weight.")
return attrs
def to_representation(self, instance: product_models.Quota):
representation = super().to_representation(instance)