aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA.Avenel <avenel.alexandre@gmail.com>2013-04-07 22:14:32 +0200
committerA.Avenel <avenel.alexandre@gmail.com>2013-04-07 22:14:32 +0200
commit0d7c82b12267ed3a9ece1ca72a71cea077e9cc0f (patch)
tree664900152d10dc061e4ed723c9fc9d7781741111
parent1fa0cff180d668a8d93d24413fe7832cdbd3e826 (diff)
downloadihatemoney-mirror-0d7c82b12267ed3a9ece1ca72a71cea077e9cc0f.zip
ihatemoney-mirror-0d7c82b12267ed3a9ece1ca72a71cea077e9cc0f.tar.gz
ihatemoney-mirror-0d7c82b12267ed3a9ece1ca72a71cea077e9cc0f.tar.bz2
More code cleanup for "settle bills"
-rw-r--r--budget/models.py8
-rw-r--r--budget/templates/settle_bills.html4
-rw-r--r--budget/tests.py4
-rw-r--r--budget/web.py2
4 files changed, 9 insertions, 9 deletions
diff --git a/budget/models.py b/budget/models.py
index 1f3fa4f..49c3eb4 100644
--- a/budget/models.py
+++ b/budget/models.py
@@ -49,7 +49,7 @@ class Project(db.Model):
return balances
- def settle_bills(self):
+ def get_transactions_to_settle_bill(self):
"""Return a list of transactions that could be made to settle the bill"""
credits, debts, transactions = [],[],[]
# Create lists of credits and debts
@@ -63,17 +63,17 @@ class Project(db.Model):
match = self.exactmatch(credit["balance"], debts)
if match:
for m in match:
- transactions.append({"ower": m["person"], "payer": credit["person"], "amount": m["balance"]})
+ transactions.append({"ower": m["person"], "receiver": credit["person"], "amount": m["balance"]})
debts.remove(m)
credits.remove(credit)
# Split any remaining debts & credits
while credits and debts:
if credits[0]["balance"] > debts[0]["balance"]:
- transactions.append({"ower": debts[0]["person"], "payer": credits[0]["person"], "amount": debts[0]["balance"]})
+ transactions.append({"ower": debts[0]["person"], "receiver": credits[0]["person"], "amount": debts[0]["balance"]})
credits[0]["balance"] = credits[0]["balance"] - debts[0]["balance"]
del debts[0]
else:
- transactions.append({"ower": debts[0]["person"], "payer": credits[0]["person"], "amount": credits[0]["balance"]})
+ transactions.append({"ower": debts[0]["person"], "receiver": credits[0]["person"], "amount": credits[0]["balance"]})
debts[0]["balance"] = debts[0]["balance"] - credits[0]["balance"]
del credits[0]
return transactions
diff --git a/budget/templates/settle_bills.html b/budget/templates/settle_bills.html
index 309642a..e2041f5 100644
--- a/budget/templates/settle_bills.html
+++ b/budget/templates/settle_bills.html
@@ -34,9 +34,9 @@
<thead><tr><th>{{ _("Who pays?") }}</th><th>{{ _("To whom?") }}</th><th>{{ _("How much?") }}</th></tr></thead>
<tbody>
{% for bill in bills %}
- <tr class="{{ loop.cycle("odd", "even") }}" owers={{bill.owers|join(',','id')}} payer={{bill.payer.id}}>
+ <tr class="{{ loop.cycle("odd", "even") }}" receiver={{bill.receiver.id}}>
<td>{{ bill.ower }}</td>
- <td>{{ bill.payer }}</td>
+ <td>{{ bill.receiver }}</td>
<td>{{ "%0.2f"|format(bill.amount) }}</td>
</tr>
{% endfor %}
diff --git a/budget/tests.py b/budget/tests.py
index 983b352..901924b 100644
--- a/budget/tests.py
+++ b/budget/tests.py
@@ -510,12 +510,12 @@ class BudgetTestCase(TestCase):
'amount': '10',
})
project = models.Project.query.get('raclette')
- transactions = project.settle_bills()
+ transactions = project.get_transactions_to_settle_bill()
members = defaultdict(int)
#We should have the same values between transactions and project balances
for t in transactions:
members[t['ower']]-=t['amount']
- members[t['payer']]+=t['amount']
+ members[t['receiver']]+=t['amount']
balance = models.Project.query.get("raclette").balance
for m, a in members.items():
self.assertEqual(a, balance[m.id])
diff --git a/budget/web.py b/budget/web.py
index f975587..3125f9b 100644
--- a/budget/web.py
+++ b/budget/web.py
@@ -386,7 +386,7 @@ def change_lang(lang):
@main.route("/<project_id>/settle_bills")
def settle_bill():
"""Compute the sum each one have to pay to each other and display it"""
- bills = g.project.settle_bills()
+ bills = g.project.get_transactions_to_settle_bill()
return render_template("settle_bills.html", bills=bills)