1
0

Allow integers as assetamount amounts
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 22s

This commit is contained in:
Jon Michael Aanes 2025-07-15 21:29:14 +02:00
parent 866459842d
commit fdf30c0f3c

View File

@ -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,