mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-05 12:41: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):
|
||||
return Bill(
|
||||
float(self.amount.data),
|
||||
self.date.data,
|
||||
self.external_link.data,
|
||||
str(self.original_currency.data),
|
||||
Person.query.get_by_ids(self.payed_for.data, project),
|
||||
self.payer.data,
|
||||
project.default_currency,
|
||||
self.what.data,
|
||||
amount=float(self.amount.data),
|
||||
date=self.date.data,
|
||||
external_link=self.external_link.data,
|
||||
original_currency=str(self.original_currency.data),
|
||||
owers=Person.query.get_by_ids(self.payed_for.data, project),
|
||||
payer_id=self.payer.data,
|
||||
project_default_currency=project.default_currency,
|
||||
what=self.what.data,
|
||||
)
|
||||
|
||||
def save(self, bill, project):
|
||||
|
|
|
@ -325,27 +325,27 @@ class Project(db.Model):
|
|||
def import_bills(self, bills: list):
|
||||
"""Import bills from a list of dictionaries"""
|
||||
# Add members not already in the project
|
||||
members_project = [str(m) for m in self.members]
|
||||
members_new = [
|
||||
m for m in get_members(bills) if str(m[0]) not in members_project
|
||||
project_members = [str(m) for m in self.members]
|
||||
new_members = [
|
||||
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])
|
||||
db.session.commit()
|
||||
|
||||
# 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}
|
||||
for b in bills:
|
||||
same = False
|
||||
for b_p in bills_project:
|
||||
if same_bill(b_p, b):
|
||||
for p_b in project_bills:
|
||||
if same_bill(p_b, b):
|
||||
same = True
|
||||
break
|
||||
if not same:
|
||||
# Create bills
|
||||
db.session.add(
|
||||
Bill(
|
||||
try:
|
||||
new_bill = Bill(
|
||||
amount=b["amount"],
|
||||
date=parse(b["date"]),
|
||||
external_link="",
|
||||
|
@ -355,7 +355,9 @@ class Project(db.Model):
|
|||
project_default_currency=self.default_currency,
|
||||
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()
|
||||
|
||||
def remove_member(self, member_id):
|
||||
|
|
|
@ -158,7 +158,12 @@ def csv2list_of_dicts(csv_to_convert):
|
|||
reader = csv.DictReader(csv_file)
|
||||
result = []
|
||||
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":
|
||||
continue
|
||||
elif r["what"] == "categoryname":
|
||||
|
|
Loading…
Reference in a new issue