From fdf30c0f3c41691fa9b4540ad3a3a9bb60f1e6a2 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Tue, 15 Jul 2025 21:29:14 +0200 Subject: [PATCH] Allow integers as assetamount amounts --- fin_defs/data.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fin_defs/data.py b/fin_defs/data.py index 4200953..29a62ec 100644 --- a/fin_defs/data.py +++ b/fin_defs/data.py @@ -494,17 +494,18 @@ class AssetAmount: """ asset: Asset - amount: Decimal + amount: Decimal | int def __post_init__(self): assert isinstance(self.asset, Asset), 'Incorrect value for self.asset' - assert isinstance(self.amount, Decimal), 'Incorrect value for self.amount' + assert isinstance(self.amount, Decimal | int), 'Incorrect value for self.amount' def __str__(self) -> str: return self.human_readable_str() def human_readable_str(self) -> str: - abs_amount = abs(self.amount) + amount = Decimal(self.amount) + abs_amount = abs(amount) # Determine specificity specificity = '3' @@ -515,7 +516,7 @@ class AssetAmount: display = ASSET_DISPLAY.get(self.asset, UNKNOWN_ASSET_DISPLAY) return ('{sign}{prefix}{amount:.' + specificity + 'f}{suffix} {name}').format( - sign='-' if (self.amount == self.amount and self.amount < 0) else '', + sign='-' if (amount == amount and amount < 0) else '', prefix=display.prefix or '', suffix=f' {display.suffix}' if display.suffix else '', amount=abs_amount,