Allow integers as assetamount amounts
This commit is contained in:
parent
866459842d
commit
fdf30c0f3c
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user