fix - calculate my stat remaining weight

This commit is contained in:
2025-11-19 16:07:22 +03:30
parent 1bf6950ccb
commit f633e24d90

View File

@@ -135,21 +135,24 @@ class QuotaStatsService:
@staticmethod
def _propagate_inventory(organization, quota, diff):
org = organization
stat_queryset = OrganizationQuotaStats.objects.select_related('quota', 'organization')
update_my_remaining_stat = True
while org:
stat = OrganizationQuotaStats.objects.filter(
stat = stat_queryset.filter(
organization=org,
quota=quota
).first()
if stat:
print(stat.id)
print(org.id, quota.id)
stat.inventory_received = (stat.inventory_received or 0) + diff
print(stat.remaining_amount)
stat.remaining_amount = stat.remaining_amount - diff
# just update my own stat remaining quota weight
if update_my_remaining_stat:
stat.remaining_amount -= diff
update_my_remaining_stat = False
if stat.inventory_received < 0:
stat.inventory_received = 0
stat.save(update_fields=['inventory_received', 'remaining_amount'])
org = org.parent_organization