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"
        ))
