Skip to content

Commit

Permalink
Reformat code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptiste Jonglez committed Mar 25, 2024
1 parent 133fa70 commit a8fc9b7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 54 deletions.
7 changes: 6 additions & 1 deletion ihatemoney/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,12 @@ class BillForm(FlaskForm):
payed_for = SelectMultipleField(
_("For whom?"), validators=[DataRequired()], coerce=int
)
bill_type = SelectField(_("Bill Type"), choices=BillType.choices(), coerce=BillType, default=BillType.EXPENSE)
bill_type = SelectField(
_("Bill Type"),
choices=BillType.choices(),
coerce=BillType,
default=BillType.EXPENSE,
)
submit = SubmitField(_("Submit"))
submit2 = SubmitField(_("Submit and add a new one"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def upgrade():
billtype_enum = sa.Enum(BillType)
billtype_enum.create(op.get_bind(), checkfirst=True)

op.add_column("bill", sa.Column("bill_type", billtype_enum, server_default=BillType.EXPENSE.name))
op.add_column(
"bill",
sa.Column("bill_type", billtype_enum, server_default=BillType.EXPENSE.name),
)
op.add_column("bill_version", sa.Column("bill_type", sa.UnicodeText()))


Expand All @@ -28,4 +31,4 @@ def downgrade():
op.drop_column("bill_version", "bill_type")

billtype_enum = sa.Enum(BillType)
billtype_enum.drop(op.get_bind())
billtype_enum.drop(op.get_bind())
7 changes: 5 additions & 2 deletions ihatemoney/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
],
)


class BillType(Enum):
EXPENSE = "Expense"
REIMBURSEMENT = "Reimbursement"
Expand Down Expand Up @@ -131,7 +132,9 @@ def full_balance(self):
if bill.bill_type == BillType.EXPENSE:
should_receive[bill.payer.id] += bill.converted_amount
for ower in bill.owers:
should_pay[ower.id] += (ower.weight * bill.converted_amount / total_weight)
should_pay[ower.id] += (
ower.weight * bill.converted_amount / total_weight
)

if bill.bill_type == BillType.REIMBURSEMENT:
should_receive[bill.payer.id] += bill.converted_amount
Expand Down Expand Up @@ -563,7 +566,7 @@ def create_demo_project():
("Alice", 20, ("Amina", "Alice"), "Beer !", "Expense"),
("Amina", 50, ("Amina", "Alice", "Georg"), "AMAP", "Expense"),
)
for (payer, amount, owers, what, bill_type) in operations:
for payer, amount, owers, what, bill_type in operations:
db.session.add(
Bill(
amount=amount,
Expand Down
8 changes: 3 additions & 5 deletions ihatemoney/tests/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,6 @@ def test_amount_too_high(self):
def test_validate_bill_type(self):
self.api_create("raclette")
self.api_add_member("raclette", "zorglub")


req = self.client.post(
"/api/projects/raclette/bills",
Expand All @@ -1029,7 +1028,7 @@ def test_validate_bill_type(self):
"bill_type": "wrong_bill_type",
"amount": "50",
},
headers=self.get_auth("raclette")
headers=self.get_auth("raclette"),
)

self.assertStatus(400, req)
Expand All @@ -1044,7 +1043,7 @@ def test_validate_bill_type(self):
"bill_type": "Expense",
"amount": "50",
},
headers=self.get_auth("raclette")
headers=self.get_auth("raclette"),
)

self.assertStatus(201, req)
Expand All @@ -1063,7 +1062,7 @@ def test_default_bill_type(self):
"payed_for": ["1"],
"amount": "50",
},
headers=self.get_auth("raclette")
headers=self.get_auth("raclette"),
)

self.assertStatus(201, req)
Expand All @@ -1076,4 +1075,3 @@ def test_default_bill_type(self):
# Bill type should now be "Expense"
got = json.loads(req.data.decode("utf-8"))
assert got["bill_type"] == "Expense"

98 changes: 54 additions & 44 deletions ihatemoney/tests/budget_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,8 @@ def test_manage_bills(self):
"amount": "17",
},
)
#transfer bill should not affect balances at all

# transfer bill should not affect balances at all
self.client.post(
"/raclette/add",
data={
Expand Down Expand Up @@ -801,22 +801,22 @@ def test_reimbursement_bill(self):
self.client.post("/rent/members/add", data={"name": "alice"})

members_ids = [m.id for m in self.get_project("rent").members]
# create a bill to test reimbursement
# create a bill to test reimbursement
self.client.post(
"/rent/add",
data={
"date": "2022-12-12",
"what": "december rent",
"payer": members_ids[0], #bob
"payed_for": members_ids, #bob and alice
"payer": members_ids[0], # bob
"payed_for": members_ids, # bob and alice
"bill_type": "Expense",
"amount": "1000",
},
)
#check balance
# check balance
balance = self.get_project("rent").balance
assert set(balance.values()), set([500 == -500])
#check paid
# check paid
bob_paid = self.get_project("rent").full_balance[2][members_ids[0]]
alice_paid = self.get_project("rent").full_balance[2][members_ids[1]]
assert bob_paid == 1000
Expand All @@ -828,20 +828,21 @@ def test_reimbursement_bill(self):
data={
"date": "2022-12-13",
"what": "reimbursement for rent",
"payer": members_ids[1], #alice
"payed_for": members_ids[0], #bob
"payer": members_ids[1], # alice
"payed_for": members_ids[0], # bob
"bill_type": "Reimbursement",
"amount": "500",
},
)

balance = self.get_project("rent").balance
assert set(balance.values()), set([0 == 0])
#check paid
# check paid
bob_paid = self.get_project("rent").full_balance[2][members_ids[0]]
alice_paid = self.get_project("rent").full_balance[2][members_ids[1]]
assert bob_paid == 500
assert alice_paid == 500

def test_transfer_bill(self):
self.post_project("random")

Expand All @@ -855,8 +856,8 @@ def test_transfer_bill(self):
data={
"date": "2022-10-10",
"what": "Rent",
"payer": members_ids[0], #zorglub
"payed_for": members_ids, #zorglub + fred
"payer": members_ids[0], # zorglub
"payed_for": members_ids, # zorglub + fred
"bill_type": "Expense",
"amount": "1000",
},
Expand All @@ -867,8 +868,8 @@ def test_transfer_bill(self):
data={
"date": "2022-10-10",
"what": "Transfer of 500 to fred",
"payer": members_ids[0], #zorglub
"payed_for": members_ids[1], #fred
"payer": members_ids[0], # zorglub
"payed_for": members_ids[1], # fred
"bill_type": "Transfer",
"amount": "500",
},
Expand All @@ -884,22 +885,22 @@ def test_reimbursement_bill(self):
self.client.post("/rent/members/add", data={"name": "alice"})

members_ids = [m.id for m in self.get_project("rent").members]
# create a bill to test reimbursement
# create a bill to test reimbursement
self.client.post(
"/rent/add",
data={
"date": "2022-12-12",
"what": "december rent",
"payer": members_ids[0], #bob
"payed_for": members_ids, #bob and alice
"payer": members_ids[0], # bob
"payed_for": members_ids, # bob and alice
"bill_type": "Expense",
"amount": "1000",
},
)
#check balance
# check balance
balance = self.get_project("rent").balance
assert set(balance.values()), set([500 == -500])
#check paid
# check paid
bob_paid = self.get_project("rent").full_balance[2][members_ids[0]]
alice_paid = self.get_project("rent").full_balance[2][members_ids[1]]
assert bob_paid == 1000
Expand All @@ -911,20 +912,21 @@ def test_reimbursement_bill(self):
data={
"date": "2022-12-13",
"what": "reimbursement for rent",
"payer": members_ids[1], #alice
"payed_for": members_ids[0], #bob
"payer": members_ids[1], # alice
"payed_for": members_ids[0], # bob
"bill_type": "Reimbursement",
"amount": "500",
},
)

balance = self.get_project("rent").balance
assert set(balance.values()), set([0 == 0])
#check paid
# check paid
bob_paid = self.get_project("rent").full_balance[2][members_ids[0]]
alice_paid = self.get_project("rent").full_balance[2][members_ids[1]]
assert bob_paid == 500
assert alice_paid == 500

def test_transfer_bill(self):
self.post_project("random")

Expand All @@ -938,8 +940,8 @@ def test_transfer_bill(self):
data={
"date": "2022-10-10",
"what": "Rent",
"payer": members_ids[0], #zorglub
"payed_for": members_ids, #zorglub + fred
"payer": members_ids[0], # zorglub
"payed_for": members_ids, # zorglub + fred
"bill_type": "Expense",
"amount": "1000",
},
Expand All @@ -950,8 +952,8 @@ def test_transfer_bill(self):
data={
"date": "2022-10-10",
"what": "Transfer of 500 to fred",
"payer": members_ids[0], #zorglub
"payed_for": members_ids[1], #fred
"payer": members_ids[0], # zorglub
"payed_for": members_ids[1], # fred
"bill_type": "Transfer",
"amount": "500",
},
Expand Down Expand Up @@ -1433,7 +1435,7 @@ def test_settle(self):
for m, a in members.items():
assert abs(a - balance[m.id]) < 0.01
return

def test_settle_button(self):
self.post_project("raclette")

Expand Down Expand Up @@ -1482,16 +1484,24 @@ def test_settle_button(self):
)
project = self.get_project("raclette")
transactions = project.get_transactions_to_settle_bill()

count = 0
for t in transactions:
count+=1
self.client.get("/raclette/settle"+"/"+str(t["amount"])+"/"+str(t["ower"].id)+"/"+str(t["receiver"].id))
count += 1
self.client.get(
"/raclette/settle"
+ "/"
+ str(t["amount"])
+ "/"
+ str(t["ower"].id)
+ "/"
+ str(t["receiver"].id)
)
temp_transactions = project.get_transactions_to_settle_bill()
#test if the one has disappeared
assert len(temp_transactions) == len(transactions)-count
#test if theres a new one with bill_type reimbursement
# test if the one has disappeared
assert len(temp_transactions) == len(transactions) - count

# test if theres a new one with bill_type reimbursement
bill = project.get_newest_bill()
assert bill.bill_type == models.BillType.REIMBURSEMENT
return
Expand Down Expand Up @@ -2005,7 +2015,7 @@ def test_rss_feed(self):
"payed_for": [1, 2, 3],
"amount": "12",
"original_currency": "EUR",
"bill_type": "Expense"
"bill_type": "Expense",
},
)
self.client.post(
Expand All @@ -2017,7 +2027,7 @@ def test_rss_feed(self):
"payed_for": [1, 2],
"amount": "15",
"original_currency": "EUR",
"bill_type": "Expense"
"bill_type": "Expense",
},
)
self.client.post(
Expand All @@ -2029,7 +2039,7 @@ def test_rss_feed(self):
"payed_for": [1, 2],
"amount": "10",
"original_currency": "EUR",
"bill_type": "Expense"
"bill_type": "Expense",
},
)

Expand Down Expand Up @@ -2092,7 +2102,7 @@ def test_rss_feed_history_disabled(self):
"payed_for": [1, 2, 3],
"amount": "12",
"original_currency": "EUR",
"bill_type": "Expense"
"bill_type": "Expense",
},
)
self.client.post(
Expand All @@ -2104,7 +2114,7 @@ def test_rss_feed_history_disabled(self):
"payed_for": [1, 2],
"amount": "15",
"original_currency": "EUR",
"bill_type": "Expense"
"bill_type": "Expense",
},
)
self.client.post(
Expand All @@ -2116,7 +2126,7 @@ def test_rss_feed_history_disabled(self):
"payed_for": [1, 2],
"amount": "10",
"original_currency": "EUR",
"bill_type": "Expense"
"bill_type": "Expense",
},
)

Expand Down Expand Up @@ -2195,7 +2205,7 @@ def test_rss_if_modified_since_header(self):
"payed_for": [1],
"amount": "12",
"original_currency": "XXX",
"bill_type": "Expense"
"bill_type": "Expense",
},
follow_redirects=True,
)
Expand Down Expand Up @@ -2364,7 +2374,7 @@ def test_remember_payer_per_project(self):
"payer": members_ids[1],
"payed_for": members_ids,
"amount": "25",
"bill_type": "Expense"
"bill_type": "Expense",
},
)

Expand All @@ -2382,7 +2392,7 @@ def test_remember_payer_per_project(self):
"payer": members_ids_tartif[2],
"payed_for": members_ids_tartif,
"amount": "24",
"bill_type": "Expense"
"bill_type": "Expense",
},
)

Expand Down Expand Up @@ -2417,7 +2427,7 @@ def test_remember_payed_for(self):
"payer": members_ids[1],
"payed_for": members_ids[1:],
"amount": "25",
"bill_type": "Expense"
"bill_type": "Expense",
},
)

Expand Down

0 comments on commit a8fc9b7

Please sign in to comment.