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 """Take a csv in-memory file and turns it into
a list of dictionnaries a list of dictionnaries
""" """
csv_file = TextIOWrapper(csv_to_convert) csv_file = TextIOWrapper(csv_to_convert, encoding="utf-8")
reader = csv.DictReader(csv_file) reader = csv.DictReader(csv_file)
result = [] result = []
for r in reader: for r in reader:
# cospend filtering
if r["what"] == "deleteMeIfYouWant":
continue
elif r["what"] == "categoryname":
break
r["amount"] = float(r["amount"]) r["amount"] = float(r["amount"])
r["payer_weight"] = float(r["payer_weight"]) r["payer_weight"] = float(r["payer_weight"])
r["owers"] = [o.strip() for o in r["owers"].split(",")] r["owers"] = [o.strip() for o in r["owers"].split(",")]

View file

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