fix - change transaction base from distribution to quota stat
This commit is contained in:
23
apps/herd/management/commands/fix_herd_status_of_rancher.py
Normal file
23
apps/herd/management/commands/fix_herd_status_of_rancher.py
Normal 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"
|
||||
))
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user