make account balance string formatting more rigid
This commit is contained in:
parent
1d21fbae5a
commit
a430c81624
@ -1,3 +1,4 @@
|
|||||||
|
from decimal import Decimal
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ from src.ez_lan_manager.types.User import User
|
|||||||
|
|
||||||
class AccountPage(Component):
|
class AccountPage(Component):
|
||||||
user: Optional[User] = None
|
user: Optional[User] = None
|
||||||
balance: Optional[int] = None
|
balance: Optional[Decimal] = None
|
||||||
transaction_history: list[Transaction] = list()
|
transaction_history: list[Transaction] = list()
|
||||||
banking_info_revealer_open: bool = False
|
banking_info_revealer_open: bool = False
|
||||||
paypal_info_revealer_open: bool = False
|
paypal_info_revealer_open: bool = False
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import logging
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from decimal import Decimal, ROUND_DOWN
|
from decimal import Decimal, ROUND_DOWN
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from src.ez_lan_manager.services.DatabaseService import DatabaseService
|
from src.ez_lan_manager.services.DatabaseService import DatabaseService
|
||||||
from src.ez_lan_manager.types.Transaction import Transaction
|
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)
|
return await self._db_service.get_all_transactions_for_user(user_id)
|
||||||
|
|
||||||
@staticmethod
|
@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.
|
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))
|
rounded_decimal = str(euros.quantize(Decimal(".01"), rounding=ROUND_DOWN))
|
||||||
return f"{rounded_decimal} €"
|
return f"{rounded_decimal} €"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user