mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-29 09:52:36 +02:00
Change statistics data structure
Clearer data structure, and simpler template This commit has a side effect: sidebar now hides disabled members. IMHO, the disabled members should either be hidden or shown consistently between sidebar and central table. Previous status was: shown in sidebar (if balance ≠ 0) and hidden in central table.
This commit is contained in:
parent
389c7b8bcd
commit
b1a4572e8c
3 changed files with 35 additions and 35 deletions
|
@ -3,12 +3,11 @@
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
<div id="table_overflow">
|
<div id="table_overflow">
|
||||||
<table class="balance table">
|
<table class="balance table">
|
||||||
{% set balance = g.project.balance %}
|
{% for stat in members_stats| sort(attribute='member.name') %}
|
||||||
{% for member in g.project.members | sort(attribute='name') if member.activated or balance[member.id]|round(2) != 0 %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="balance-name">{{ member.name }}</td>
|
<td class="balance-name">{{ stat.member.name }}</td>
|
||||||
<td class="balance-value {% if balance[member.id]|round(2) > 0 %}positive{% elif balance[member.id]|round(2) < 0 %}negative{% endif %}">
|
<td class="balance-value {% if stat.balance|round(2) > 0 %}positive{% elif stat.balance|round(2) < 0 %}negative{% endif %}">
|
||||||
{% if balance[member.id]|round(2) > 0 %}+{% endif %}{{ "%.2f" | format(balance[member.id]) }}
|
{% if stat.balance|round(2) > 0 %}+{% endif %}{{ "%.2f" | format(stat.balance) }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -21,12 +20,12 @@
|
||||||
<table id="bill_table" class="split_bills table table-striped">
|
<table id="bill_table" class="split_bills table table-striped">
|
||||||
<thead><tr><th>{{ _("Who?") }}</th><th>{{ _("Paid") }}</th><th>{{ _("Spent") }}</th><th>{{ _("Balance") }}</th></tr></thead>
|
<thead><tr><th>{{ _("Who?") }}</th><th>{{ _("Paid") }}</th><th>{{ _("Spent") }}</th><th>{{ _("Balance") }}</th></tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for member in members %}
|
{% for stat in members_stats %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ member.name }}</td>
|
<td>{{ stat.member.name }}</td>
|
||||||
<td>{{ "%0.2f"|format(paid[member.id]) }}</td>
|
<td>{{ "%0.2f"|format(stat.paid) }}</td>
|
||||||
<td>{{ "%0.2f"|format(spent[member.id]) }}</td>
|
<td>{{ "%0.2f"|format(stat.spent) }}</td>
|
||||||
<td>{{ "%0.2f"|format(balance[member.id]) }}</td>
|
<td>{{ "%0.2f"|format(stat.balance) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -750,24 +750,24 @@ class BudgetTestCase(IhatemoneyTestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
response = self.client.get("/raclette/statistics")
|
response = self.client.get("/raclette/statistics")
|
||||||
self.assertIn("<td>alexis</td>\n "
|
self.assertIn("<td>alexis</td>\n "
|
||||||
+ "<td>20.00</td>\n "
|
+ "<td>20.00</td>\n "
|
||||||
+ "<td>31.67</td>\n "
|
+ "<td>31.67</td>\n "
|
||||||
+ "<td>-11.67</td>\n",
|
+ "<td>-11.67</td>\n",
|
||||||
response.data.decode('utf-8'))
|
response.data.decode('utf-8'))
|
||||||
self.assertIn("<td>fred</td>\n "
|
self.assertIn("<td>fred</td>\n "
|
||||||
+ "<td>20.00</td>\n "
|
+ "<td>20.00</td>\n "
|
||||||
+ "<td>5.83</td>\n "
|
+ "<td>5.83</td>\n "
|
||||||
+ "<td>14.17</td>\n",
|
+ "<td>14.17</td>\n",
|
||||||
response.data.decode('utf-8'))
|
response.data.decode('utf-8'))
|
||||||
self.assertIn("<td>tata</td>\n "
|
self.assertIn("<td>tata</td>\n "
|
||||||
+ "<td>0.00</td>\n "
|
+ "<td>0.00</td>\n "
|
||||||
+ "<td>2.50</td>\n "
|
+ "<td>2.50</td>\n "
|
||||||
+ "<td>-2.50</td>\n",
|
+ "<td>-2.50</td>\n",
|
||||||
response.data.decode('utf-8'))
|
response.data.decode('utf-8'))
|
||||||
self.assertIn("<td>toto</td>\n "
|
self.assertIn("<td>toto</td>\n "
|
||||||
+ "<td>0.00</td>\n "
|
+ "<td>0.00</td>\n "
|
||||||
+ "<td>0.00</td>\n "
|
+ "<td>0.00</td>\n "
|
||||||
+ "<td>0.00</td>\n",
|
+ "<td>0.00</td>\n",
|
||||||
response.data.decode('utf-8'))
|
response.data.decode('utf-8'))
|
||||||
|
|
||||||
|
|
|
@ -566,21 +566,22 @@ def settle_bill():
|
||||||
@main.route("/<project_id>/statistics")
|
@main.route("/<project_id>/statistics")
|
||||||
def statistics():
|
def statistics():
|
||||||
"""Compute what each member has paid and spent and display it"""
|
"""Compute what each member has paid and spent and display it"""
|
||||||
members = g.project.active_members
|
members_stats = [{
|
||||||
balance = g.project.balance
|
'member': member,
|
||||||
paid = {}
|
'paid': sum([
|
||||||
spent = {}
|
bill.amount
|
||||||
for member in members:
|
for bill in g.project.get_member_bills(member.id).all()
|
||||||
paid[member.id] = sum([bill.amount
|
]),
|
||||||
for bill in g.project.get_member_bills(member.id).all()])
|
'spent': sum([
|
||||||
spent[member.id] = sum([bill.pay_each() * member.weight
|
bill.pay_each() * member.weight
|
||||||
for bill in g.project.get_bills().all() if member in bill.owers])
|
for bill in g.project.get_bills().all() if member in bill.owers
|
||||||
|
]),
|
||||||
|
'balance': g.project.balance[member.id]
|
||||||
|
} for member in g.project.active_members]
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"statistics.html",
|
"statistics.html",
|
||||||
members=members,
|
members_stats=members_stats,
|
||||||
balance=balance,
|
|
||||||
paid=paid,
|
|
||||||
spent=spent,
|
|
||||||
current_view='statistics',
|
current_view='statistics',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue