diff options
author | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-07 00:17:03 -0600 |
---|---|---|
committer | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-07 00:17:03 -0600 |
commit | 4875c36a055ea89118e665bdd8b3d0148b112307 (patch) | |
tree | 594c19c52c336f5950ea58d5c8be5a8d11cdd4d4 /utils/register.py | |
parent | 579fdc4a200aa0560fb063fae79c84c14ca73c30 (diff) | |
download | Ledger.py-4875c36a055ea89118e665bdd8b3d0148b112307.tar.gz Ledger.py-4875c36a055ea89118e665bdd8b3d0148b112307.zip |
We can now compare currencies.
At least with just the `<` and if we only have one type of currency. The
value is the only thing that will be compared.
Diffstat (limited to 'utils/register.py')
-rw-r--r-- | utils/register.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/utils/register.py b/utils/register.py index 8ebb5b6..0a103fb 100644 --- a/utils/register.py +++ b/utils/register.py @@ -101,6 +101,18 @@ class currencies: return negated + def __lt__(self, other): + if len(self.money.values()) != 1 or len(other.money.values()) != 1: + raise Exception('Cannot compare multiple currencies at once!') + + for amount_left in self.money.values(): + break + for amount_right in other.money.values(): + break + + return amount_left < amount_right + + def complete_prices(my_entry: entry): """ Transform all string of prices to the class `currencies`. If there is an |