1
0

Additional verification
Some checks failed
Python Ruff Code Quality / ruff (push) Failing after 22s
Run Python tests (through Pytest) / Test (push) Failing after 25s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 21s

This commit is contained in:
Jon Michael Aanes 2025-05-14 13:15:19 +02:00
parent b05f889144
commit 028124e427

View File

@ -512,15 +512,26 @@ class AssetAmount:
asset: Asset asset: Asset
amount: Decimal amount: Decimal
def __post_init__(self):
assert isinstance(self.asset, Asset), 'Incorrect value for self.asset'
assert isinstance(self.amount, Decimal), 'Incorrect value for self.amount'
def __str__(self) -> str: def __str__(self) -> str:
return self.human_readable_str() return self.human_readable_str()
def human_readable_str(self) -> str: def human_readable_str(self) -> str:
abs_amount = abs(self.amount) abs_amount = abs(self.amount)
specificity = '2' if abs_amount >= THREE_DECIMALS_UNDER_THIS_AMOUNT else '3'
# Determine specificity
specificity = '3'
if abs_amount != abs_amount:
specificity = '0'
elif abs_amount >= THREE_DECIMALS_UNDER_THIS_AMOUNT:
specificity = '2'
prefix = ASSET_PREFIX.get(self.asset, '') prefix = ASSET_PREFIX.get(self.asset, '')
return ('{sign}{prefix}{amount:.' + specificity + 'f} {name}').format( return ('{sign}{prefix}{amount:.' + specificity + 'f} {name}').format(
sign='-' if self.amount < 0 else '', sign='-' if (self.amount == self.amount and self.amount < 0) else '',
prefix=prefix, prefix=prefix,
amount=abs_amount, amount=abs_amount,
name=self.asset.raw_short_name(), name=self.asset.raw_short_name(),