fix - change transaction base from distribution to quota stat

This commit is contained in:
2025-11-26 15:28:14 +03:30
parent 7c1fb57934
commit 817f26519d
13 changed files with 568 additions and 30 deletions

View File

@@ -0,0 +1,23 @@
from django.core.management.base import BaseCommand
from django.db.models import Count
from apps.herd.models import Rancher
class Command(BaseCommand):
help = "Fast update ranchers without herds using bulk updates"
def handle(self, *args, **kwargs):
self.stdout.write("🔄 Bulk updating ranchers...")
no_herd_count = Rancher.objects.annotate(
herd_count=Count("herd")
).filter(herd_count=0).update(without_herd=True)
has_herd_count = Rancher.objects.annotate(
herd_count=Count("herd")
).filter(herd_count__gt=0).update(without_herd=False)
self.stdout.write(self.style.SUCCESS(
f"✅ Done! {no_herd_count} set to True, {has_herd_count} set to False"
))

View File

@@ -167,6 +167,7 @@ def rancher_quota_weight(
"total_weight": total_weight,
"remaining_weight": remaining_weight,
'free_sale': free_sale,
'total_purchase': 0,
"rancher_temporary_livestock": rancher.without_herd,
"by_type": [{
"name": key,