cospend compatible import

This commit is contained in:
Youe Graillot 2021-11-28 02:58:10 +01:00
parent e7d991ecc2
commit 61df8aaffb
2 changed files with 9 additions and 9 deletions

View file

@ -154,10 +154,15 @@ def csv2list_of_dicts(csv_to_convert):
"""Take a csv in-memory file and turns it into
a list of dictionnaries
"""
csv_file = TextIOWrapper(csv_to_convert)
csv_file = TextIOWrapper(csv_to_convert, encoding="utf-8")
reader = csv.DictReader(csv_file)
result = []
for r in reader:
# cospend filtering
if r["what"] == "deleteMeIfYouWant":
continue
elif r["what"] == "categoryname":
break
r["amount"] = float(r["amount"])
r["payer_weight"] = float(r["payer_weight"])
r["owers"] = [o.strip() for o in r["owers"].split(",")]

View file

@ -477,14 +477,9 @@ def import_project():
# set it to project default.
if e.get("currency", "") in ["", "XXX"]:
e["currency"] = g.project.default_currency
if len(e) != len(attr):
raise ValueError(_("Invalid JSON"))
list_attr = []
for i in e:
list_attr.append(i)
list_attr.sort()
if list_attr != attr:
raise ValueError(_("Invalid JSON"))
for a in attr:
if a not in e:
raise ValueError(_("Missing attribute {}").format(a))
# Keep track of currencies
currencies.add(e["currency"])