From 82e8c4f9fbc2a9435d9d71ed1d673546e571c340 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 4 Nov 2025 14:42:24 +0330 Subject: [PATCH] fix - compare weight in distribution with parent or none --- .../v1/serializers/quota_distribution_serializers.py | 12 ++++++++++-- logs/django_requests.log | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/apps/product/web/api/v1/serializers/quota_distribution_serializers.py b/apps/product/web/api/v1/serializers/quota_distribution_serializers.py index 47a7de0..2964dfb 100644 --- a/apps/product/web/api/v1/serializers/quota_distribution_serializers.py +++ b/apps/product/web/api/v1/serializers/quota_distribution_serializers.py @@ -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 diff --git a/logs/django_requests.log b/logs/django_requests.log index 9b98921..fd9b716 100644 --- a/logs/django_requests.log +++ b/logs/django_requests.log @@ -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