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