fix - compare weight in distribution with parent or none
This commit is contained in:
@@ -38,6 +38,7 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
||||
assigned_organization = data['assigned_organization']
|
||||
amount = data['weight']
|
||||
instance_id = self.instance.id if self.instance else None
|
||||
parent_distribution = data['parent_distribution'] or None
|
||||
|
||||
# check quota expired time
|
||||
if not quota.is_in_valid_time():
|
||||
@@ -57,8 +58,15 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
||||
).exclude(id=instance_id).aggregate(
|
||||
total=models.Sum('weight')
|
||||
)['total'] or 0
|
||||
if total + amount > quota.quota_weight:
|
||||
raise QuotaWeightException()
|
||||
|
||||
# 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:
|
||||
if parent_distribution.weight + amount > parent_distribution.weight:
|
||||
raise QuotaWeightException()
|
||||
|
||||
if self.instance:
|
||||
# total warehouse inventory entry
|
||||
|
||||
Reference in New Issue
Block a user