mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-05 20:51:49 +02:00
various fixes from review
This commit is contained in:
parent
07f23ce91e
commit
fbd8c69708
3 changed files with 26 additions and 19 deletions
|
@ -323,14 +323,14 @@ class BillForm(FlaskForm):
|
||||||
|
|
||||||
def export(self, project):
|
def export(self, project):
|
||||||
return Bill(
|
return Bill(
|
||||||
float(self.amount.data),
|
amount=float(self.amount.data),
|
||||||
self.date.data,
|
date=self.date.data,
|
||||||
self.external_link.data,
|
external_link=self.external_link.data,
|
||||||
str(self.original_currency.data),
|
original_currency=str(self.original_currency.data),
|
||||||
Person.query.get_by_ids(self.payed_for.data, project),
|
owers=Person.query.get_by_ids(self.payed_for.data, project),
|
||||||
self.payer.data,
|
payer_id=self.payer.data,
|
||||||
project.default_currency,
|
project_default_currency=project.default_currency,
|
||||||
self.what.data,
|
what=self.what.data,
|
||||||
)
|
)
|
||||||
|
|
||||||
def save(self, bill, project):
|
def save(self, bill, project):
|
||||||
|
|
|
@ -325,27 +325,27 @@ class Project(db.Model):
|
||||||
def import_bills(self, bills: list):
|
def import_bills(self, bills: list):
|
||||||
"""Import bills from a list of dictionaries"""
|
"""Import bills from a list of dictionaries"""
|
||||||
# Add members not already in the project
|
# Add members not already in the project
|
||||||
members_project = [str(m) for m in self.members]
|
project_members = [str(m) for m in self.members]
|
||||||
members_new = [
|
new_members = [
|
||||||
m for m in get_members(bills) if str(m[0]) not in members_project
|
m for m in get_members(bills) if str(m[0]) not in project_members
|
||||||
]
|
]
|
||||||
for m in members_new:
|
for m in new_members:
|
||||||
Person(name=m[0], project=self, weight=m[1])
|
Person(name=m[0], project=self, weight=m[1])
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Import bills not already in the project
|
# Import bills not already in the project
|
||||||
bills_project = self.get_pretty_bills()
|
project_bills = self.get_pretty_bills()
|
||||||
id_dict = {m.name: m.id for m in self.members}
|
id_dict = {m.name: m.id for m in self.members}
|
||||||
for b in bills:
|
for b in bills:
|
||||||
same = False
|
same = False
|
||||||
for b_p in bills_project:
|
for p_b in project_bills:
|
||||||
if same_bill(b_p, b):
|
if same_bill(p_b, b):
|
||||||
same = True
|
same = True
|
||||||
break
|
break
|
||||||
if not same:
|
if not same:
|
||||||
# Create bills
|
# Create bills
|
||||||
db.session.add(
|
try:
|
||||||
Bill(
|
new_bill = Bill(
|
||||||
amount=b["amount"],
|
amount=b["amount"],
|
||||||
date=parse(b["date"]),
|
date=parse(b["date"]),
|
||||||
external_link="",
|
external_link="",
|
||||||
|
@ -355,7 +355,9 @@ class Project(db.Model):
|
||||||
project_default_currency=self.default_currency,
|
project_default_currency=self.default_currency,
|
||||||
what=b["what"],
|
what=b["what"],
|
||||||
)
|
)
|
||||||
)
|
except Exception as e:
|
||||||
|
raise ValueError(f"Unable to import csv data: {repr(e)}")
|
||||||
|
db.session.add(new_bill)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
def remove_member(self, member_id):
|
def remove_member(self, member_id):
|
||||||
|
|
|
@ -158,7 +158,12 @@ def csv2list_of_dicts(csv_to_convert):
|
||||||
reader = csv.DictReader(csv_file)
|
reader = csv.DictReader(csv_file)
|
||||||
result = []
|
result = []
|
||||||
for r in reader:
|
for r in reader:
|
||||||
# cospend filtering
|
"""
|
||||||
|
cospend embeds various data helping (cospend) imports
|
||||||
|
'deleteMeIfYouWant' lines contains users
|
||||||
|
'categoryname' table contains categories description
|
||||||
|
we don't need them as we determine users and categories from bills
|
||||||
|
"""
|
||||||
if r["what"] == "deleteMeIfYouWant":
|
if r["what"] == "deleteMeIfYouWant":
|
||||||
continue
|
continue
|
||||||
elif r["what"] == "categoryname":
|
elif r["what"] == "categoryname":
|
||||||
|
|
Loading…
Reference in a new issue