feat(cof_clubs): List archived accounting periods for buro
This commit is contained in:
parent
cf14b4e3fb
commit
4f631689f2
2 changed files with 29 additions and 7 deletions
|
@ -60,8 +60,18 @@
|
|||
Ajouter des budgets en masse (AGB)
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% for a in archived_accounting_periods %}
|
||||
{% if forloop.first %}
|
||||
<h1>Exercices archivés</h1>
|
||||
<ul>
|
||||
{% endif %}
|
||||
<li><a href="{% url 'cof_clubs:acct-period-update' a.id %}">{{ a.name }}</a></li>
|
||||
{% if forloop.last %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
|
@ -46,10 +46,14 @@ class ClubListView(LoginRequiredMixin, TemplateView):
|
|||
def get_context_data(self, *args, **kwargs):
|
||||
ctx = super().get_context_data(*args, **kwargs)
|
||||
|
||||
accounting_periods = ClubBudgetAccountingPeriod.objects.filter(
|
||||
is_archived=False
|
||||
).values("name", "id")
|
||||
# Retrieve accounting periods
|
||||
accounting_periods = ClubBudgetAccountingPeriod.objects.all()
|
||||
active_accounting_periods = accounting_periods.filter(is_archived=False).values(
|
||||
"name", "id"
|
||||
)
|
||||
archived_accounting_periods = accounting_periods.filter(is_archived=True)
|
||||
|
||||
# Retrieve clubs managed by the user (buro manage everything)
|
||||
if self.request.user.profile.is_buro:
|
||||
managed_clubs = Club.objects.all().order_by("name") # TODO useless
|
||||
else:
|
||||
|
@ -57,6 +61,8 @@ class ClubListView(LoginRequiredMixin, TemplateView):
|
|||
self.request.user.managed_budgets_set.all()
|
||||
| self.request.user.respo_set.all()
|
||||
).order_by("name")
|
||||
|
||||
# Retrieve global budget data
|
||||
data = (
|
||||
ClubBudgetLine.objects.filter(
|
||||
accounting_period__is_archived=False, club__in=managed_clubs
|
||||
|
@ -68,19 +74,25 @@ class ClubListView(LoginRequiredMixin, TemplateView):
|
|||
)
|
||||
.annotate(Sum("amount"))
|
||||
)
|
||||
|
||||
# Structure budget data
|
||||
structured_data = {
|
||||
club.id: {
|
||||
"name": club.name,
|
||||
"amounts": [0 for _ in accounting_periods],
|
||||
"amounts": [0 for _ in active_accounting_periods],
|
||||
}
|
||||
for club in managed_clubs
|
||||
}
|
||||
period_to_index = {a["id"]: i for i, a in enumerate(accounting_periods)}
|
||||
# Helper to map accounting_period.id -> index in amounts list
|
||||
period_to_index = {a["id"]: i for i, a in enumerate(active_accounting_periods)}
|
||||
|
||||
# Fill structured data
|
||||
for d in data:
|
||||
structured_data[d["club"]]["amounts"][
|
||||
period_to_index[d["accounting_period"]]
|
||||
] = d["amount__sum"]
|
||||
ctx["accounting_periods"] = accounting_periods
|
||||
ctx["accounting_periods"] = active_accounting_periods
|
||||
ctx["archived_accounting_periods"] = archived_accounting_periods
|
||||
ctx["clubs"] = structured_data
|
||||
return ctx
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue