From a430c81624b2c2a586bbe00591782b2a9d885889 Mon Sep 17 00:00:00 2001 From: David Rodenkirchen Date: Tue, 25 Mar 2025 21:10:39 +0100 Subject: [PATCH] make account balance string formatting more rigid --- src/ez_lan_manager/pages/Account.py | 3 ++- src/ez_lan_manager/services/AccountingService.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ez_lan_manager/pages/Account.py b/src/ez_lan_manager/pages/Account.py index beda11c..a60b742 100644 --- a/src/ez_lan_manager/pages/Account.py +++ b/src/ez_lan_manager/pages/Account.py @@ -1,3 +1,4 @@ +from decimal import Decimal from functools import partial from typing import Optional @@ -12,7 +13,7 @@ from src.ez_lan_manager.types.User import User class AccountPage(Component): user: Optional[User] = None - balance: Optional[int] = None + balance: Optional[Decimal] = None transaction_history: list[Transaction] = list() banking_info_revealer_open: bool = False paypal_info_revealer_open: bool = False diff --git a/src/ez_lan_manager/services/AccountingService.py b/src/ez_lan_manager/services/AccountingService.py index 5970631..469c901 100644 --- a/src/ez_lan_manager/services/AccountingService.py +++ b/src/ez_lan_manager/services/AccountingService.py @@ -2,6 +2,7 @@ import logging from collections.abc import Callable from datetime import datetime from decimal import Decimal, ROUND_DOWN +from typing import Optional from src.ez_lan_manager.services.DatabaseService import DatabaseService from src.ez_lan_manager.types.Transaction import Transaction @@ -65,9 +66,11 @@ class AccountingService: return await self._db_service.get_all_transactions_for_user(user_id) @staticmethod - def make_euro_string_from_decimal(euros: Decimal) -> str: + def make_euro_string_from_decimal(euros: Optional[Decimal]) -> str: """ Internally, all money values are euros as decimal. Only when showing them to the user we generate a string. """ + if euros is None: + return "0.00 €" rounded_decimal = str(euros.quantize(Decimal(".01"), rounding=ROUND_DOWN)) return f"{rounded_decimal} €"