add - whole system of inventory entry in organization quotas stat

This commit is contained in:
2025-11-19 15:56:15 +03:30
parent 42c01f3eb5
commit 1bf6950ccb
9 changed files with 152 additions and 34 deletions

View File

@@ -16,24 +16,21 @@ class WarehouseAllocationService:
with transaction.atomic():
distributions = QuotaDistribution.objects.filter(
assigned_organization=entry.organization,
quota=entry.distribution.quota
quota=entry.quota
).select_related('quota').order_by('-create_date')
if not distributions.exists():
raise WareHouseException("توزیعی برای این انبار وجود ندارد", status.HTTP_403_FORBIDDEN) # noqa
remaining = entry.weight
for dist in distributions:
if remaining <= 0:
break
stat = OrganizationQuotaStats.objects.get(
quota=dist.quota,
organization=dist.assigned_organization
)
capacity = stat.remaining_amount
if capacity <= 0:
continue
@@ -46,6 +43,7 @@ class WarehouseAllocationService:
)
stat.inventory_received += allocate_weight
stat.remaining_amount -= allocate_weight
stat.save()
remaining -= allocate_weight
@@ -55,3 +53,13 @@ class WarehouseAllocationService:
"مقدار وارد شده از انبار بیشتر از مقدار کل سهمیه توزیع داده شده است", # noqa
status.HTTP_400_BAD_REQUEST
)
org = entry.organization.parent_organization
while org:
stat = OrganizationQuotaStats.objects.get(
quota=entry.quota,
organization=org
)
stat.inventory_received += entry.weight
stat.save()
org = org.parent_organization