From c3d53904b4b0428ee8975f2ce087daa1d7e3b6e4 Mon Sep 17 00:00:00 2001 From: Kersten Weise Date: Tue, 10 Dec 2024 16:10:05 +0100 Subject: [PATCH] Requested changes done --- tapir/accounts/templates/accounts/user_detail.html | 4 +++- .../management/commands/process_credit_account.py | 4 ++-- tapir/statistics/templatetags/statistics.py | 9 +++++---- .../commands/generate_test_data_functions.py | 12 +++--------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/tapir/accounts/templates/accounts/user_detail.html b/tapir/accounts/templates/accounts/user_detail.html index f862ec80..4231021d 100644 --- a/tapir/accounts/templates/accounts/user_detail.html +++ b/tapir/accounts/templates/accounts/user_detail.html @@ -149,7 +149,9 @@
{% purchase_tracking_card tapir_user=object %} {% if tapir_user.share_owner and tapir_user.allows_purchase_tracking %}
{% purchase_statistics_card tapir_user=object %}
- + {% endif %} + + {% if tapir_user.share_owner and tapir_user.allows_purchase_tracking %}
{% credit_account_card tapir_user=object %}
diff --git a/tapir/statistics/management/commands/process_credit_account.py b/tapir/statistics/management/commands/process_credit_account.py index a7a6e3dd..f0d424b0 100644 --- a/tapir/statistics/management/commands/process_credit_account.py +++ b/tapir/statistics/management/commands/process_credit_account.py @@ -15,7 +15,7 @@ from tapir.accounts.models import TapirUser from tapir.statistics.models import ProcessedCreditFiles, CreditAccount from tapir.utils.shortcuts import get_timezone_aware_datetime -from tapir.statistics.management.commands import process_purchase_files +from tapir.statistics.management.commands.process_purchase_files import Command class Command(BaseCommand): @@ -67,7 +67,7 @@ def process_file(cls, file: SFTPFile, file_name: str): CreditAccount.objects.create( source_file=source_file, credit_date=credit_date, - credit_amount=process_purchase_files.parse_german_number(row["Betrag"]), + credit_amount=Command.parse_german_number(row["Betrag"]), credit_counter=row["Bon"], cashier=row["Kasse"], info=row["Info"], diff --git a/tapir/statistics/templatetags/statistics.py b/tapir/statistics/templatetags/statistics.py index ab039fad..bca52c74 100644 --- a/tapir/statistics/templatetags/statistics.py +++ b/tapir/statistics/templatetags/statistics.py @@ -25,10 +25,11 @@ def purchase_statistics_card(context, tapir_user): @register.inclusion_tag("statistics/tags/credit_account_card.html", takes_context=True) def credit_account_card(context, tapir_user): user_credits = CreditAccount.objects.filter(tapir_user=tapir_user) - context["last_credits"] = user_credits.order_by("-credit_date")[:10] - context["actual_credit"] = "{:.2f}".format( - user_credits.aggregate(total_credit=Sum("credit_amount"))["total_credit"] - ) + if user_credits: + context["last_credits"] = user_credits.order_by("-credit_date")[:10] + context["actual_credit"] = "{:.2f}".format( + user_credits.aggregate(total_credit=Sum("credit_amount"))["total_credit"] + ) return context diff --git a/tapir/utils/management/commands/generate_test_data_functions.py b/tapir/utils/management/commands/generate_test_data_functions.py index f97cb64b..4979f380 100644 --- a/tapir/utils/management/commands/generate_test_data_functions.py +++ b/tapir/utils/management/commands/generate_test_data_functions.py @@ -595,17 +595,11 @@ def generate_credit_account(): share_owners = NumberOfSharesService.annotate_share_owner_queryset_with_nb_of_active_shares( share_owners, current_date ) - # share_owners = ( - # MembershipPauseService.annotate_share_owner_queryset_with_has_active_pause( - # share_owners, current_date - # ) - # ) - - purchasing_users = [ + credit_users = [ share_owner for share_owner in share_owners.with_status( status=MemberStatus.ACTIVE, at_datetime=current_date - ) + )[::2] if share_owner.user ] info = random.choice(["Guthabenkarte", "Einkauf"]) @@ -628,7 +622,7 @@ def generate_credit_account(): info=info, tapir_user=share_owner.user, ) - for share_owner in purchasing_users + for share_owner in credit_users ] )