quota stat by organization - v1

This commit is contained in:
2025-11-15 16:04:41 +03:30
parent afc9def177
commit ec6637569d
10 changed files with 168 additions and 13 deletions

View File

@@ -87,9 +87,6 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
if not self.instance.parent_distribution:
if amount + total > self.instance.quota.quota_weight:
raise APIException("وزن وارد شده بیشتر از وزن باقیمانده است", code=403) # noqa
# else:
# if amount > self.instance.parent_distribution.remaining_weight:
# raise QuotaWeightException()
return data

View File

@@ -10,8 +10,15 @@ class QuotaSerializer(serializers.ModelSerializer):
model = product_models.Quota
fields = '__all__'
def to_representation(self, instance):
def to_representation(self, instance: product_models.Quota):
representation = super().to_representation(instance)
# change quota weight by organization received weight
if self.context['org']:
quota_weight_by_org = instance.quota_amount_by_org(self.context['org'])
if quota_weight_by_org:
representation['quota_weight'] = quota_weight_by_org
if isinstance(instance, product_models.Quota):
if instance.sale_unit:
representation['sale_unit'] = product_serializers.SaleUnitSerializer(