add - whole system of inventory entry in organization quotas stat
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user