mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-28 17:32:38 +02:00
Reformat code with black and isort
This commit is contained in:
parent
a0409a296a
commit
312dfef14b
5 changed files with 75 additions and 56 deletions
|
@ -364,7 +364,12 @@ class BillForm(FlaskForm):
|
||||||
payed_for = SelectMultipleField(
|
payed_for = SelectMultipleField(
|
||||||
_("For whom?"), validators=[DataRequired()], coerce=int
|
_("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"))
|
submit = SubmitField(_("Submit"))
|
||||||
submit2 = SubmitField(_("Submit and add a new one"))
|
submit2 = SubmitField(_("Submit and add a new one"))
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,10 @@ def upgrade():
|
||||||
billtype_enum = sa.Enum(BillType)
|
billtype_enum = sa.Enum(BillType)
|
||||||
billtype_enum.create(op.get_bind(), checkfirst=True)
|
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()))
|
op.add_column("bill_version", sa.Column("bill_type", sa.UnicodeText()))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from enum import Enum
|
|
||||||
import datetime
|
import datetime
|
||||||
|
from enum import Enum
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
|
@ -22,7 +22,7 @@ from sqlalchemy_continuum.plugins import FlaskPlugin
|
||||||
|
|
||||||
from ihatemoney.currency_convertor import CurrencyConverter
|
from ihatemoney.currency_convertor import CurrencyConverter
|
||||||
from ihatemoney.monkeypath_continuum import PatchedTransactionFactory
|
from ihatemoney.monkeypath_continuum import PatchedTransactionFactory
|
||||||
from ihatemoney.utils import generate_password_hash, get_members, same_bill, FormEnum
|
from ihatemoney.utils import generate_password_hash, get_members, same_bill
|
||||||
from ihatemoney.versioning import (
|
from ihatemoney.versioning import (
|
||||||
ConditionalVersioningManager,
|
ConditionalVersioningManager,
|
||||||
LoggingMode,
|
LoggingMode,
|
||||||
|
@ -51,6 +51,7 @@ make_versioned(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BillType(Enum):
|
class BillType(Enum):
|
||||||
EXPENSE = "Expense"
|
EXPENSE = "Expense"
|
||||||
REIMBURSEMENT = "Reimbursement"
|
REIMBURSEMENT = "Reimbursement"
|
||||||
|
@ -131,7 +132,9 @@ class Project(db.Model):
|
||||||
if bill.bill_type == BillType.EXPENSE:
|
if bill.bill_type == BillType.EXPENSE:
|
||||||
should_receive[bill.payer.id] += bill.converted_amount
|
should_receive[bill.payer.id] += bill.converted_amount
|
||||||
for ower in bill.owers:
|
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:
|
if bill.bill_type == BillType.REIMBURSEMENT:
|
||||||
should_receive[bill.payer.id] += bill.converted_amount
|
should_receive[bill.payer.id] += bill.converted_amount
|
||||||
|
@ -563,7 +566,7 @@ class Project(db.Model):
|
||||||
("Alice", 20, ("Amina", "Alice"), "Beer !", "Expense"),
|
("Alice", 20, ("Amina", "Alice"), "Beer !", "Expense"),
|
||||||
("Amina", 50, ("Amina", "Alice", "Georg"), "AMAP", "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(
|
db.session.add(
|
||||||
Bill(
|
Bill(
|
||||||
amount=amount,
|
amount=amount,
|
||||||
|
|
|
@ -1018,7 +1018,6 @@ class TestAPI(IhatemoneyTestCase):
|
||||||
self.api_create("raclette")
|
self.api_create("raclette")
|
||||||
self.api_add_member("raclette", "zorglub")
|
self.api_add_member("raclette", "zorglub")
|
||||||
|
|
||||||
|
|
||||||
req = self.client.post(
|
req = self.client.post(
|
||||||
"/api/projects/raclette/bills",
|
"/api/projects/raclette/bills",
|
||||||
data={
|
data={
|
||||||
|
@ -1029,7 +1028,7 @@ class TestAPI(IhatemoneyTestCase):
|
||||||
"bill_type": "wrong_bill_type",
|
"bill_type": "wrong_bill_type",
|
||||||
"amount": "50",
|
"amount": "50",
|
||||||
},
|
},
|
||||||
headers=self.get_auth("raclette")
|
headers=self.get_auth("raclette"),
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertStatus(400, req)
|
self.assertStatus(400, req)
|
||||||
|
@ -1044,7 +1043,7 @@ class TestAPI(IhatemoneyTestCase):
|
||||||
"bill_type": "Expense",
|
"bill_type": "Expense",
|
||||||
"amount": "50",
|
"amount": "50",
|
||||||
},
|
},
|
||||||
headers=self.get_auth("raclette")
|
headers=self.get_auth("raclette"),
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertStatus(201, req)
|
self.assertStatus(201, req)
|
||||||
|
@ -1063,7 +1062,7 @@ class TestAPI(IhatemoneyTestCase):
|
||||||
"payed_for": ["1"],
|
"payed_for": ["1"],
|
||||||
"amount": "50",
|
"amount": "50",
|
||||||
},
|
},
|
||||||
headers=self.get_auth("raclette")
|
headers=self.get_auth("raclette"),
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertStatus(201, req)
|
self.assertStatus(201, req)
|
||||||
|
@ -1076,4 +1075,3 @@ class TestAPI(IhatemoneyTestCase):
|
||||||
# Bill type should now be "Expense"
|
# Bill type should now be "Expense"
|
||||||
got = json.loads(req.data.decode("utf-8"))
|
got = json.loads(req.data.decode("utf-8"))
|
||||||
assert got["bill_type"] == "Expense"
|
assert got["bill_type"] == "Expense"
|
||||||
|
|
||||||
|
|
|
@ -842,6 +842,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
alice_paid = self.get_project("rent").full_balance[2][members_ids[1]]
|
alice_paid = self.get_project("rent").full_balance[2][members_ids[1]]
|
||||||
assert bob_paid == 500
|
assert bob_paid == 500
|
||||||
assert alice_paid == 500
|
assert alice_paid == 500
|
||||||
|
|
||||||
def test_transfer_bill(self):
|
def test_transfer_bill(self):
|
||||||
self.post_project("random")
|
self.post_project("random")
|
||||||
|
|
||||||
|
@ -925,6 +926,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
alice_paid = self.get_project("rent").full_balance[2][members_ids[1]]
|
alice_paid = self.get_project("rent").full_balance[2][members_ids[1]]
|
||||||
assert bob_paid == 500
|
assert bob_paid == 500
|
||||||
assert alice_paid == 500
|
assert alice_paid == 500
|
||||||
|
|
||||||
def test_transfer_bill(self):
|
def test_transfer_bill(self):
|
||||||
self.post_project("random")
|
self.post_project("random")
|
||||||
|
|
||||||
|
@ -1486,7 +1488,15 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
count = 0
|
count = 0
|
||||||
for t in transactions:
|
for t in transactions:
|
||||||
count += 1
|
count += 1
|
||||||
self.client.get("/raclette/settle"+"/"+str(t["amount"])+"/"+str(t["ower"].id)+"/"+str(t["receiver"].id))
|
self.client.get(
|
||||||
|
"/raclette/settle"
|
||||||
|
+ "/"
|
||||||
|
+ str(t["amount"])
|
||||||
|
+ "/"
|
||||||
|
+ str(t["ower"].id)
|
||||||
|
+ "/"
|
||||||
|
+ str(t["receiver"].id)
|
||||||
|
)
|
||||||
temp_transactions = project.get_transactions_to_settle_bill()
|
temp_transactions = project.get_transactions_to_settle_bill()
|
||||||
# test if the one has disappeared
|
# test if the one has disappeared
|
||||||
assert len(temp_transactions) == len(transactions) - count
|
assert len(temp_transactions) == len(transactions) - count
|
||||||
|
@ -2005,7 +2015,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
"payed_for": [1, 2, 3],
|
"payed_for": [1, 2, 3],
|
||||||
"amount": "12",
|
"amount": "12",
|
||||||
"original_currency": "EUR",
|
"original_currency": "EUR",
|
||||||
"bill_type": "Expense"
|
"bill_type": "Expense",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
self.client.post(
|
self.client.post(
|
||||||
|
@ -2017,7 +2027,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
"payed_for": [1, 2],
|
"payed_for": [1, 2],
|
||||||
"amount": "15",
|
"amount": "15",
|
||||||
"original_currency": "EUR",
|
"original_currency": "EUR",
|
||||||
"bill_type": "Expense"
|
"bill_type": "Expense",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
self.client.post(
|
self.client.post(
|
||||||
|
@ -2029,7 +2039,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
"payed_for": [1, 2],
|
"payed_for": [1, 2],
|
||||||
"amount": "10",
|
"amount": "10",
|
||||||
"original_currency": "EUR",
|
"original_currency": "EUR",
|
||||||
"bill_type": "Expense"
|
"bill_type": "Expense",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2092,7 +2102,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
"payed_for": [1, 2, 3],
|
"payed_for": [1, 2, 3],
|
||||||
"amount": "12",
|
"amount": "12",
|
||||||
"original_currency": "EUR",
|
"original_currency": "EUR",
|
||||||
"bill_type": "Expense"
|
"bill_type": "Expense",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
self.client.post(
|
self.client.post(
|
||||||
|
@ -2104,7 +2114,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
"payed_for": [1, 2],
|
"payed_for": [1, 2],
|
||||||
"amount": "15",
|
"amount": "15",
|
||||||
"original_currency": "EUR",
|
"original_currency": "EUR",
|
||||||
"bill_type": "Expense"
|
"bill_type": "Expense",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
self.client.post(
|
self.client.post(
|
||||||
|
@ -2116,7 +2126,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
"payed_for": [1, 2],
|
"payed_for": [1, 2],
|
||||||
"amount": "10",
|
"amount": "10",
|
||||||
"original_currency": "EUR",
|
"original_currency": "EUR",
|
||||||
"bill_type": "Expense"
|
"bill_type": "Expense",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2195,7 +2205,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
"payed_for": [1],
|
"payed_for": [1],
|
||||||
"amount": "12",
|
"amount": "12",
|
||||||
"original_currency": "XXX",
|
"original_currency": "XXX",
|
||||||
"bill_type": "Expense"
|
"bill_type": "Expense",
|
||||||
},
|
},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
@ -2364,7 +2374,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
"payer": members_ids[1],
|
"payer": members_ids[1],
|
||||||
"payed_for": members_ids,
|
"payed_for": members_ids,
|
||||||
"amount": "25",
|
"amount": "25",
|
||||||
"bill_type": "Expense"
|
"bill_type": "Expense",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2382,7 +2392,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
"payer": members_ids_tartif[2],
|
"payer": members_ids_tartif[2],
|
||||||
"payed_for": members_ids_tartif,
|
"payed_for": members_ids_tartif,
|
||||||
"amount": "24",
|
"amount": "24",
|
||||||
"bill_type": "Expense"
|
"bill_type": "Expense",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2417,7 +2427,7 @@ class TestBudget(IhatemoneyTestCase):
|
||||||
"payer": members_ids[1],
|
"payer": members_ids[1],
|
||||||
"payed_for": members_ids[1:],
|
"payed_for": members_ids[1:],
|
||||||
"amount": "25",
|
"amount": "25",
|
||||||
"bill_type": "Expense"
|
"bill_type": "Expense",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue