Verified Commit 862896c2 authored by Jakob Moser's avatar Jakob Moser
Browse files

Move to_decimal_if_numeric helper to money.py

parent e01dd322
Loading
Loading
Loading
Loading
+0 −10
Changes for poolpay/admin/PersonsTable.py: 0 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -10,16 +10,6 @@ from textual.widgets.data_table import ColumnKey
from poolpay.model.Person import Person


def to_decimal_if_numeric(thing: str | Text) -> str | Decimal:
    str_value = thing.plain if isinstance(thing, Text) else thing
    str_value_no_currency_symbol = re.sub(r"\s*€$", "", str_value)

    try:
        return parse_decimal(str_value_no_currency_symbol)
    except NumberFormatError:
        return str_value


def to_chunked_hex(i: int) -> str:
    i_hex = hex(i).removeprefix("0x")

poolpay/admin/money.py

0 → 100644
+15 −0
Changes for poolpay/admin/money.py: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
import re
from decimal import Decimal

from babel.numbers import NumberFormatError, parse_decimal
from rich.text import Text


def to_decimal_if_numeric(thing: str | Text) -> str | Decimal:
    str_value = thing.plain if isinstance(thing, Text) else thing
    str_value_no_currency_symbol = re.sub(r"\s*€$", "", str_value)

    try:
        return parse_decimal(str_value_no_currency_symbol)
    except NumberFormatError:
        return str_value