feat(cof_clubs): Display archived accounting periods in detail view
This commit is contained in:
parent
4364fd149e
commit
1b1e0c5288
2 changed files with 46 additions and 48 deletions
|
@ -3,14 +3,13 @@
|
|||
|
||||
{% block content %}
|
||||
|
||||
{% regroup lines by accounting_period__name as lines_list %}
|
||||
<div class="section">
|
||||
<div class="content container is-max-desktop"/>
|
||||
<h1>{{ object.name }}</h1>
|
||||
<h5>Respos:</h5>
|
||||
<div class="grid">
|
||||
{% for r in object.respos.all %}
|
||||
<div class="tag cell">{{r.username}}</div>
|
||||
<div class="tag cell is-link">{{r.username}}</div>
|
||||
{% empty %}
|
||||
<div class="tag cell is-warning">Ce club n'a pas de respo déclaré</div>
|
||||
{% endfor%}
|
||||
|
@ -20,16 +19,23 @@
|
|||
<h5>Gestionnaires additionels du budget:</h5>
|
||||
<div class="grid">
|
||||
{% for r in object.budget_managers.all %}
|
||||
<div class="tag cell">{{r.username}}</div>
|
||||
<div class="tag cell is-link">{{r.username}}</div>
|
||||
{% endfor%}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% for period in lines_list %}
|
||||
{% for period in accounting_periods %}
|
||||
<h2 class="buttons">
|
||||
{{ period.grouper }}
|
||||
<a class="button" href="{% url "cof_clubs:budget-line-create" object.id period.list.0.accounting_period__id %}"><span class="icon"><i class="fa fa-plus"></i></span></a></h2>
|
||||
{{ period.name }}
|
||||
{% if period.is_archived %}
|
||||
<div class="button is-static"><span>Archivé</span><span class="icon"><i class="fa fa-inbox"></i></span></div>
|
||||
{% else %}
|
||||
<a class="button" href="{% url "cof_clubs:budget-line-create" object.id period.id %}"><span class="icon"><i class="fa fa-plus"></i></span></a>
|
||||
{% endif %}
|
||||
</h2>
|
||||
|
||||
{% for line in period.lines %}
|
||||
{% if forloop.first %}
|
||||
<table class="table is-bordered is-striped is-fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -41,7 +47,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for line in period.list %}
|
||||
{% endif %}
|
||||
<tr>
|
||||
<td class="is-vcentered">{{ line.date|date:"SHORT_DATE_FORMAT" }}</td>
|
||||
<td class="is-vcentered">{{ line.label }}</td>
|
||||
|
@ -80,14 +86,14 @@
|
|||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% if forloop.last %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% endif %}
|
||||
{% empty %}
|
||||
<div class="tag is-primary">Le club n'a pas demandé de budget sur cet exercice.</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -115,44 +115,36 @@ class ClubDetailView(AccessMixin, DetailView):
|
|||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
ctx = super().get_context_data(*args, **kwargs)
|
||||
lines_qs = (
|
||||
ctx["object"]
|
||||
.clubbudgetline_set.filter(
|
||||
accounting_period__is_archived=False,
|
||||
club = ctx["object"]
|
||||
accounting_periods_qs = ClubBudgetAccountingPeriod.objects.prefetch_related(
|
||||
"clubbudgetline_set"
|
||||
).order_by("is_archived", "name")
|
||||
accounting_periods = accounting_periods_qs.values("name", "is_archived", "id")
|
||||
|
||||
user_manages_club = (
|
||||
self.request.user in club.respos.all()
|
||||
or self.request.user in club.budget_managers.all()
|
||||
) # We don't have to check buro here since it is checked later
|
||||
# Fill accounting period data with the budget lines
|
||||
# (and compute editing rights and partial sums)
|
||||
for i, period in enumerate(accounting_periods):
|
||||
s = 0
|
||||
lines = (
|
||||
accounting_periods_qs[i]
|
||||
.clubbudgetline_set.filter(club=club)
|
||||
.order_by("date")
|
||||
.values("amount", "label", "date", "id", "posted")
|
||||
)
|
||||
.prefetch_related("club__respos", "club__budget_managers")
|
||||
.order_by(
|
||||
"accounting_period__is_archived", "accounting_period__name", "date"
|
||||
)
|
||||
)
|
||||
lines = lines_qs.values(
|
||||
"accounting_period__name",
|
||||
"accounting_period__id",
|
||||
"date",
|
||||
"amount",
|
||||
"label",
|
||||
"id",
|
||||
"posted",
|
||||
"accounting_period__is_archived",
|
||||
)
|
||||
# Compute rights and partial sums
|
||||
s = 0
|
||||
current_period = None
|
||||
for i, line in enumerate(lines):
|
||||
if line["accounting_period__id"] != current_period:
|
||||
current_period = line["accounting_period__id"]
|
||||
s = 0
|
||||
s += line["amount"]
|
||||
line["can_edit"] = self.request.user.profile.is_buro or (
|
||||
not line["posted"]
|
||||
and not line["accounting_period__is_archived"]
|
||||
and (
|
||||
self.request.user in lines_qs[i].club.respos.all()
|
||||
or self.request.user in lines_qs[i].club.budget_managers.all()
|
||||
for j, value in enumerate(lines):
|
||||
s += value["amount"]
|
||||
value["can_edit"] = self.request.user.profile.is_buro or (
|
||||
not value["posted"]
|
||||
and not period["is_archived"]
|
||||
and user_manages_club
|
||||
)
|
||||
)
|
||||
line["remaining"] = s
|
||||
ctx["lines"] = lines
|
||||
value["remaining"] = s
|
||||
accounting_periods[i]["lines"] = lines
|
||||
ctx["accounting_periods"] = accounting_periods
|
||||
return ctx
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue