handle model changes in management commands

This commit is contained in:
2024-06-11 23:41:07 +02:00
parent 6baf5c9066
commit 572d91018d
3 changed files with 6 additions and 102 deletions
+1 -25
View File
@@ -12,7 +12,6 @@ class Command(BaseCommand):
def handle(self, *args, **options):
id_to_name = {d.id: d.name for d in Drink.objects.all()}
for user in User.objects.all().order_by("username"):
print(f">>> {user.username.capitalize()}")
to_pay = user.consumed_drinks_price
if to_pay != 0:
paid_consumption = user.consumption_list.filter(for_free=False)
@@ -21,27 +20,4 @@ class Command(BaseCommand):
name = id_to_name[drink_dict["drink_id"]]
amount = drink_dict["amount"]
drink_list.append(f"{amount}x {name}")
drink_list_str = ", ".join(drink_list)
print(f"zu zahlen: {euro(to_pay)} ({drink_list_str})")
donated = user.donations_made
if donated != 0:
don_list = [f"{don.date:%d.%m.} {euro(don.amount)}" for don in user.donations.order_by("date")]
don_list_str = ", ".join(don_list)
print(f"gespendet: {euro(donated)} ({don_list_str})")
paid = user.other_payments_made
if paid != 0:
pay_list = [f"{pay.purpose} {euro(pay.amount)}" for pay in user.payments.order_by("date")]
pay_list_str = ", ".join(pay_list)
print(f"bezahlt: {euro(paid)} ({pay_list_str})")
paid_back = user.paybacks_received
if paid_back != 0:
pb_list = [f"{pb.date:%d.%m.} {euro(pb.amount)}" for pb in user.paybacks.order_by("date")]
pb_list_str = ", ".join(pb_list)
print(f"zurückbekommen: {euro(paid_back)} ({pb_list_str})")
balance = donated + paid - to_pay - paid_back
print(f"==> STAND: {euro(balance)}")
print()
print(f"{user.username.capitalize()}: {euro(to_pay)} ({", ".join(drink_list)})")