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 %}
|
||||
<div id="table_overflow">
|
||||
<table class="balance table">
|
||||
{% set balance = g.project.balance %}
|
||||
{% for member in g.project.members | sort(attribute='name') if member.activated or balance[member.id]|round(2) != 0 %}
|
||||
{% for stat in members_stats| sort(attribute='member.name') %}
|
||||
<tr>
|
||||
<td class="balance-name">{{ member.name }}</td>
|
||||
<td class="balance-value {% if balance[member.id]|round(2) > 0 %}positive{% elif balance[member.id]|round(2) < 0 %}negative{% endif %}">
|
||||
{% if balance[member.id]|round(2) > 0 %}+{% endif %}{{ "%.2f" | format(balance[member.id]) }}
|
||||
<td class="balance-name">{{ stat.member.name }}</td>
|
||||
<td class="balance-value {% if stat.balance|round(2) > 0 %}positive{% elif stat.balance|round(2) < 0 %}negative{% endif %}">
|
||||
{% if stat.balance|round(2) > 0 %}+{% endif %}{{ "%.2f" | format(stat.balance) }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -21,12 +20,12 @@
|
|||
<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>
|
||||
<tbody>
|
||||
{% for member in members %}
|
||||
{% for stat in members_stats %}
|
||||
<tr>
|
||||
<td>{{ member.name }}</td>
|
||||
<td>{{ "%0.2f"|format(paid[member.id]) }}</td>
|
||||
<td>{{ "%0.2f"|format(spent[member.id]) }}</td>
|
||||
<td>{{ "%0.2f"|format(balance[member.id]) }}</td>
|
||||
<td>{{ stat.member.name }}</td>
|
||||
<td>{{ "%0.2f"|format(stat.paid) }}</td>
|
||||
<td>{{ "%0.2f"|format(stat.spent) }}</td>
|
||||
<td>{{ "%0.2f"|format(stat.balance) }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -566,21 +566,22 @@ def settle_bill():
|
|||
@main.route("/<project_id>/statistics")
|
||||
def statistics():
|
||||
"""Compute what each member has paid and spent and display it"""
|
||||
members = g.project.active_members
|
||||
balance = g.project.balance
|
||||
paid = {}
|
||||
spent = {}
|
||||
for member in members:
|
||||
paid[member.id] = sum([bill.amount
|
||||
for bill in g.project.get_member_bills(member.id).all()])
|
||||
spent[member.id] = sum([bill.pay_each() * member.weight
|
||||
for bill in g.project.get_bills().all() if member in bill.owers])
|
||||
members_stats = [{
|
||||
'member': member,
|
||||
'paid': sum([
|
||||
bill.amount
|
||||
for bill in g.project.get_member_bills(member.id).all()
|
||||
]),
|
||||
'spent': sum([
|
||||
bill.pay_each() * member.weight
|
||||
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(
|
||||
"statistics.html",
|
||||
members=members,
|
||||
balance=balance,
|
||||
paid=paid,
|
||||
spent=spent,
|
||||
members_stats=members_stats,
|
||||
current_view='statistics',
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue