From a32892707f78f6bd5692ea86b4ad9d2064ce7417 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sat, 22 Nov 2025 09:34:17 +0330 Subject: [PATCH] fix - warehouse allocation service --- .../web/api/v1/serializers/quota_serializers.py | 1 + .../warehouse/services/warehouse_allocation_service.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/product/web/api/v1/serializers/quota_serializers.py b/apps/product/web/api/v1/serializers/quota_serializers.py index fd4b821..86bbb59 100644 --- a/apps/product/web/api/v1/serializers/quota_serializers.py +++ b/apps/product/web/api/v1/serializers/quota_serializers.py @@ -37,6 +37,7 @@ class QuotaSerializer(serializers.ModelSerializer): representation['remaining_weight'] = quota_weight_by_org['remaining_weight'] representation['been_sold'] = quota_weight_by_org['been_sold'] representation['inventory_received'] = quota_weight_by_org['inventory_received'] + representation['inventory_entry_balance'] = quota_weight_by_org['inventory_entry_balance'] representation['distributions_number_by_me'] = instance.distributions_assigned.filter( assigner_organization=org ).count() diff --git a/apps/warehouse/services/warehouse_allocation_service.py b/apps/warehouse/services/warehouse_allocation_service.py index dc9da93..1ea1f02 100644 --- a/apps/warehouse/services/warehouse_allocation_service.py +++ b/apps/warehouse/services/warehouse_allocation_service.py @@ -56,10 +56,12 @@ class WarehouseAllocationService: org = entry.organization.parent_organization while org: - stat = OrganizationQuotaStats.objects.get( + stat = OrganizationQuotaStats.objects.filter( quota=entry.quota, organization=org ) - stat.inventory_received += entry.weight - stat.save() - org = org.parent_organization + if stat.exists(): + stat = stat.first() + stat.inventory_received += entry.weight + stat.save() + org = org.parent_organization