fix - remove child_total / not self.instanceto validate in distribution serializer
This commit is contained in:
@@ -61,14 +61,12 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
# if parent distribution is none compare with main quota weight
|
# if parent distribution is none compare with main quota weight
|
||||||
# else compare with parent distribution weight
|
# else compare with parent distribution weight
|
||||||
|
if not self.instance:
|
||||||
if not parent_distribution:
|
if not parent_distribution:
|
||||||
if total + amount > quota.quota_weight:
|
if total + amount > quota.quota_weight:
|
||||||
raise QuotaWeightException()
|
raise QuotaWeightException()
|
||||||
else:
|
else:
|
||||||
children_total = parent_distribution.children.all().aggregate(
|
if parent_distribution.remaining_weight + amount > parent_distribution.remaining_weight:
|
||||||
total=models.Sum('weight')
|
|
||||||
)['total'] or 0
|
|
||||||
if children_total + amount > parent_distribution.weight:
|
|
||||||
raise QuotaWeightException()
|
raise QuotaWeightException()
|
||||||
|
|
||||||
if self.instance:
|
if self.instance:
|
||||||
@@ -81,15 +79,16 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
|||||||
if total_entry > self.instance.weight:
|
if total_entry > self.instance.weight:
|
||||||
raise APIException("وزن وارد شده کمتر از وزن ورودی به انبار است", code=403) # noqa
|
raise APIException("وزن وارد شده کمتر از وزن ورودی به انبار است", code=403) # noqa
|
||||||
|
|
||||||
|
if self.instance.parent_distribution:
|
||||||
|
if self.instance.parent_distribution.remaining_weight + amount > self.instance.parent_distribution.remaining_weight:
|
||||||
|
raise QuotaWeightException()
|
||||||
|
|
||||||
# if weight is more than distribution remaining weight
|
# if weight is more than distribution remaining weight
|
||||||
if not self.instance.parent_distribution:
|
if not self.instance.parent_distribution:
|
||||||
if amount + total > self.instance.quota.quota_weight:
|
if amount + total > self.instance.quota.quota_weight:
|
||||||
raise APIException("وزن وارد شده بیشتر از وزن باقیمانده است", code=403) # noqa
|
raise APIException("وزن وارد شده بیشتر از وزن باقیمانده است", code=403) # noqa
|
||||||
else:
|
else:
|
||||||
children_total = self.instance.parent_distribution.children.all().aggregate(
|
if self.instance.parent_distribution.remaining_weight + amount > self.instance.parent_distribution.remaining_weight:
|
||||||
total=models.Sum('weight')
|
|
||||||
)['total'] or 0
|
|
||||||
if children_total + amount > self.instance.parent_distribution.weight:
|
|
||||||
raise QuotaWeightException()
|
raise QuotaWeightException()
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user