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

View File

@@ -1252,3 +1252,13 @@ TypeError: 'NoneType' object is not iterable
[2025-11-04 11:58:36,417] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading.
[2025-11-04 11:58:38,421] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
[2025-11-04 11:58:43,169] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/ HTTP/1.1" 200 428
[2025-11-04 13:25:43,249] INFO django.server | IP: - | Path: - | "GET /product/pos/api/v1/distributions/rancher_distributions?national_code=4050820765 HTTP/1.1" 301 0
[2025-11-04 13:25:44,494] INFO django.server | IP: - | Path: - | "GET /product/pos/api/v1/distributions/rancher_distributions/?national_code=4050820765 HTTP/1.1" 200 7459
[2025-11-04 13:42:58,653] INFO django.server | IP: - | Path: - | "GET /product/pos/api/v1/distributions/rancher_distributions?national_code=4050820765 HTTP/1.1" 301 0
[2025-11-04 13:42:59,922] INFO django.server | IP: - | Path: - | "GET /product/pos/api/v1/distributions/rancher_distributions/?national_code=4050820765 HTTP/1.1" 200 8028
[2025-11-04 13:47:33,773] INFO django.server | IP: - | Path: - | "GET /product/pos/api/v1/distributions/rancher_distributions?national_code=4050820765 HTTP/1.1" 301 0
[2025-11-04 13:47:35,216] INFO django.server | IP: - | Path: - | "GET /product/pos/api/v1/distributions/rancher_distributions/?national_code=4050820765 HTTP/1.1" 200 8474
[2025-11-04 13:56:49,656] INFO django.server | IP: - | Path: - | "GET /product/pos/api/v1/distributions/rancher_distributions?national_code=4050820765 HTTP/1.1" 301 0
[2025-11-04 13:56:49,907] INFO django.server | IP: - | Path: - | "GET /product/pos/api/v1/distributions/rancher_distributions/?national_code=4050820765 HTTP/1.1" 200 135
[2025-11-04 14:41:31,421] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\product\web\api\v1\serializers\quota_distribution_serializers.py changed, reloading.
[2025-11-04 14:41:36,126] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader