From 847b8dc9f678c42c73ca40b5c795a460c0e6e94e Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sat, 22 Nov 2025 12:27:30 +0330 Subject: [PATCH] fix - update registerer quota stat in wqrehous allocation service --- .../services/warehouse_allocation_service.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/apps/warehouse/services/warehouse_allocation_service.py b/apps/warehouse/services/warehouse_allocation_service.py index ce06ed0..e3b89af 100644 --- a/apps/warehouse/services/warehouse_allocation_service.py +++ b/apps/warehouse/services/warehouse_allocation_service.py @@ -55,13 +55,25 @@ class WarehouseAllocationService: ) org = entry.organization.parent_organization + parent_orgs = [] while org: - stat = OrganizationQuotaStats.objects.filter( - quota=entry.quota, - organization=org - ) - if stat.exists(): - stat = stat.first() - stat.inventory_received += entry.weight - stat.save() + # import parent org to list + parent_orgs.append(org) org = org.parent_organization + + parent_org_ids = [org.id for org in parent_orgs] + + target_org_ids = set(parent_org_ids) + + if entry.quota.registerer_organization.id not in target_org_ids: + target_org_ids.add(entry.quota.registerer_organization.id) + + stats = (OrganizationQuotaStats.objects.filter( + quota=entry.quota, + organization__in=target_org_ids + )) + + for stat in stats: + stat.inventory_received += entry.weight + + OrganizationQuotaStats.objects.bulk_update(stats, ["inventory_received"])