aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAdrián Oliva <adrian.oliva@cimat.mx>2023-05-07 17:48:41 -0600
committerAdrián Oliva <adrian.oliva@cimat.mx>2023-05-07 17:48:41 -0600
commit2dcabff113476a18dadf1e281c013115902c2059 (patch)
tree476cbfd083a81dee5c27b0b4a2bf13e8553fcc3a /utils
parent674c382afa00d65c550e141a2a758b9b1e348178 (diff)
downloadLedger.py-2dcabff113476a18dadf1e281c013115902c2059.tar.gz
Ledger.py-2dcabff113476a18dadf1e281c013115902c2059.zip
`currencies` class can now convert to string.
Before we had to iterate and immediatly stop. Now if there's only one type of currency, we can return the string of it.
Diffstat (limited to 'utils')
-rw-r--r--utils/register.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/utils/register.py b/utils/register.py
index 0a103fb..b067e56 100644
--- a/utils/register.py
+++ b/utils/register.py
@@ -85,11 +85,11 @@ class currencies:
"""
if not self.money:
yield '0'
- for currency, number in self.money.items():
+ for currency, amount in self.money.items():
if len(currency) == 1:
- yield f'{currency}{number:.02f}'
+ yield f'{currency}{amount:.02f}'
else:
- yield f'{number:.02f} {currency}'
+ yield f'{amount:.02f} {currency}'
# What to do if we do "-currencies"?
@@ -113,6 +113,17 @@ class currencies:
return amount_left < amount_right
+ def __str__(self) -> str:
+ if len(self.money.items()) != 1:
+ raise Exception('Cannot convert to string more than one currency!')
+
+ for currency, amount in self.money.items():
+ if len(currency) == 1:
+ return f'{currency}{amount:.02f}'
+ else:
+ return f'{amount:.02f} {currency}'
+
+
def complete_prices(my_entry: entry):
"""
Transform all string of prices to the class `currencies`. If there is an