From 3cbe276a69d7f7f4f08468258be48202f5ff3774 Mon Sep 17 00:00:00 2001 From: zorun Date: Sun, 1 Aug 2021 16:46:50 +0200 Subject: [PATCH] Simplify import code Co-authored-by: Glandos --- ihatemoney/web.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/ihatemoney/web.py b/ihatemoney/web.py index 63692110..712d2b0e 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -452,12 +452,10 @@ def import_project(file, project): attr.sort() currencies = set() for e in json_file: - # Add compatibility with versions < 5 that did not have currencies - if "currency" not in e: - e["currency"] = CurrencyConverter.no_currency - # Empty currency should be converted to "XXX" - if e["currency"] == "": - e["currency"] = CurrencyConverter.no_currency + # If currency is absent, empty, or explicitly set to XXX + # set it to project default. + if e.get("currency", "") in ["", "XXX"]: + e["currency"] = project.default_currency if len(e) != len(attr): raise ValueError(_("Invalid JSON")) list_attr = [] @@ -466,12 +464,6 @@ def import_project(file, project): list_attr.sort() if list_attr != attr: raise ValueError(_("Invalid JSON")) - # If the project has a default currency, convert bills that have no currency - if ( - project.default_currency != CurrencyConverter.no_currency - and e["currency"] == CurrencyConverter.no_currency - ): - e["currency"] = project.default_currency # Keep track of currencies currencies.add(e["currency"])