fix - showing my devices

This commit is contained in:
2025-12-17 16:08:45 +03:30
parent 34aac97eaa
commit 6e0c7d14c9
7 changed files with 58 additions and 5 deletions

View File

@@ -0,0 +1,25 @@
from django.core.management.base import BaseCommand
from apps.warehouse.models import InventoryQuotaSaleTransaction
class Command(BaseCommand):
help = "Fix Ranchers FullName on Transactions"
def handle(self, *args, **kwargs):
self.stdout.write("🔄 Bulk updating ranchers...")
trans_list = []
transactions = InventoryQuotaSaleTransaction.objects.all()
for trans in transactions:
if trans.rancher:
trans.rancher_fullname = trans.rancher.first_name + " " + trans.rancher.last_name if trans.rancher.last_name else ""
print(trans.rancher_fullname)
trans_list.append(trans)
self.stdout.write(" Bulk updating ranchers started...")
InventoryQuotaSaleTransaction.objects.bulk_update(trans_list, fields=['rancher_fullname'])
self.stdout.write(self.style.SUCCESS(
f"✅ Done! {0} set to True, {0} set to False"
))

View File

@@ -0,0 +1,28 @@
from django.core.management.base import BaseCommand
from apps.herd.models import Rancher
class Command(BaseCommand):
help = "Fix Ranchers FirstName & LastName On Ranching Farm"
def handle(self, *args, **kwargs):
self.stdout.write("🔄 Bulk updating ranchers...")
ranchers_list = []
ranchers = Rancher.objects.all()
for rancher in ranchers:
if rancher.ranching_farm:
if not rancher.first_name or not rancher.last_name:
split_ranching_farm = rancher.ranching_farm.split(" ")
rancher.first_name = split_ranching_farm[0]
rancher.last_name = " ".join(split_ranching_farm[1:]) if len(split_ranching_farm) >= 2 else None
ranchers_list.append(rancher)
print(rancher.first_name, "--->", rancher.last_name)
self.stdout.write(" Bulk updating ranchers started...")
Rancher.objects.bulk_update(ranchers_list, fields=['first_name', 'last_name'])
self.stdout.write(self.style.SUCCESS(
f"✅ Done! {0} set to True, {0} set to False"
))