fix - compare weight in distribution with parent or none

This commit is contained in:
2025-11-04 14:42:24 +03:30
parent 95921aa8b4
commit 82e8c4f9fb
2 changed files with 20 additions and 2 deletions

View File

@@ -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