mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-05 12:41:49 +02:00
cospend compatible import
This commit is contained in:
parent
e7d991ecc2
commit
61df8aaffb
2 changed files with 9 additions and 9 deletions
|
@ -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(",")]
|
||||||
|
|
|
@ -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"])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue