diff --git a/src/backoffice/templates/chain_detail_backoffice.html b/src/backoffice/templates/chain_detail_backoffice.html index 987bc9a88..0d6f60dee 100644 --- a/src/backoffice/templates/chain_detail_backoffice.html +++ b/src/backoffice/templates/chain_detail_backoffice.html @@ -55,6 +55,17 @@

{{ expenses.count }} Expenses for Chain {{ chain.name }}

{{ revenues.count }} Revenues for Chain {{ chain.name }}

{% include 'includes/revenue_list_panel.html' with revenue_list=revenues %} +
+ +

{{ past_expenses.count }} Expenses for Chain {{ chain.name }} in previous years

+ {% include 'includes/expense_list_panel.html' with expense_list=past_expenses past_camps=True %} + +
+ +

{{ past_revenues.count }} Revenues for Chain {{ chain.name }} in previous years

+ {% include 'includes/revenue_list_panel.html' with revenue_list=past_revenues past_camps=True %} + + diff --git a/src/backoffice/templates/expense_detail_backoffice.html b/src/backoffice/templates/expense_detail_backoffice.html index d1af5a58d..a3490e064 100644 --- a/src/backoffice/templates/expense_detail_backoffice.html +++ b/src/backoffice/templates/expense_detail_backoffice.html @@ -25,5 +25,6 @@

Manage Expense

Open in Admin {% endif %} Back to Expense List + Back to Chain Details {% endblock content %} diff --git a/src/backoffice/templates/revenue_detail_backoffice.html b/src/backoffice/templates/revenue_detail_backoffice.html index 3fce77024..c9d838e38 100644 --- a/src/backoffice/templates/revenue_detail_backoffice.html +++ b/src/backoffice/templates/revenue_detail_backoffice.html @@ -24,5 +24,6 @@

Manage Revenue

Open in Admin {% endif %} Back to Revenue List + Back to Chain Details {% endblock content %} diff --git a/src/backoffice/views/economy.py b/src/backoffice/views/economy.py index fa1033316..ebabb74bf 100644 --- a/src/backoffice/views/economy.py +++ b/src/backoffice/views/economy.py @@ -165,6 +165,17 @@ def get_context_data(self, *args, **kwargs): camp=self.camp, debtor__chain=self.get_object(), ).prefetch_related("responsible_team", "user", "debtor") + + # Include past years expenses and revenues for the Chain in context as separate querysets + context["past_expenses"] = Expense.objects.filter( + camp__camp__lt=self.camp.camp, + creditor__chain=self.get_object(), + ).prefetch_related("responsible_team", "user", "creditor") + context["past_revenues"] = Revenue.objects.filter( + camp__camp__lt=self.camp.camp, + debtor__chain=self.get_object(), + ).prefetch_related("responsible_team", "user", "debtor") + return context diff --git a/src/economy/templates/chain_list.html b/src/economy/templates/chain_list.html index f89fa9de5..c99f8ef10 100644 --- a/src/economy/templates/chain_list.html +++ b/src/economy/templates/chain_list.html @@ -13,6 +13,7 @@

Chains

{% if chain_list %}

Existing Chains

+ Italic: No current expenses for this year
{% for chain in chain_list %} @@ -25,6 +26,19 @@

{% endif %} {% endfor %} + {% if past_year_chains %} +
+ {% for chain in past_year_chains %} + +

+ {{ chain.name }} ({{ chain.credebtors.count }} credebtors) +

+ {% if chain.notes %} +

{{ chain.notes }}

+ {% endif %} +
+ {% endfor %} + {% endif %}

diff --git a/src/economy/templates/credebtor_list.html b/src/economy/templates/credebtor_list.html index bdf271f0a..ce8717878 100644 --- a/src/economy/templates/credebtor_list.html +++ b/src/economy/templates/credebtor_list.html @@ -15,7 +15,7 @@

Existing Credebtors

- {% for credebtor in chain.credebtors.all %} + {% for credebtor in credebtor_list %} diff --git a/src/economy/templates/includes/expense_list_panel.html b/src/economy/templates/includes/expense_list_panel.html index a7aced8a2..cc4371058 100644 --- a/src/economy/templates/includes/expense_list_panel.html +++ b/src/economy/templates/includes/expense_list_panel.html @@ -4,6 +4,9 @@ + {% if past_camps %} + + {% endif %} {% if not reimbursement %} @@ -24,9 +27,12 @@ {% for expense in expense_list %} {% if request.resolver_match.app_name == "backoffice" %} - + {% else %} - + + {% endif %} + {% if past_camps %} + {% endif %} @@ -43,9 +49,9 @@ diff --git a/src/economy/templates/includes/revenue_list_panel.html b/src/economy/templates/includes/revenue_list_panel.html index 6a306b03d..d0f4995cc 100644 --- a/src/economy/templates/includes/revenue_list_panel.html +++ b/src/economy/templates/includes/revenue_list_panel.html @@ -4,6 +4,9 @@ + {% if past_camps %} + + {% endif %} @@ -18,6 +21,9 @@ {% for revenue in revenue_list %} + {% if past_camps %} + + {% endif %} @@ -27,14 +33,14 @@ diff --git a/src/economy/views.py b/src/economy/views.py index baeff2771..0fce098d3 100644 --- a/src/economy/views.py +++ b/src/economy/views.py @@ -6,6 +6,9 @@ from django.conf import settings from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin +from django.db.models import OuterRef +from django.db.models import Q +from django.db.models import Prefetch from django.db.models import Sum from django.http import HttpResponse from django.http import HttpResponseRedirect @@ -64,8 +67,8 @@ def get_context_data(self, **kwargs): ).count() reimbursement_total = 0 for reimbursement in Reimbursement.objects.filter( - reimbursement_user=self.request.user, - camp=self.camp, + reimbursement_user=self.request.user, + camp=self.camp, ): reimbursement_total += reimbursement.amount context["reimbursement_total"] = reimbursement_total @@ -151,10 +154,24 @@ def form_valid(self, form): class ChainListView(CampViewMixin, RaisePermissionRequiredMixin, ListView): - model = Chain template_name = "chain_list.html" permission_required = "camps.expense_create_permission" + def get_queryset(self): + queryset = (Chain.objects + .filter(credebtors__expenses__camp=self.camp) + .order_by('name')) + + return queryset + + def get_context_data(self, **kwargs): + """Add chains with expenses in past years""" + context = super().get_context_data(**kwargs) + context['past_year_chains'] = (Chain.objects + .filter(~Q(credebtors__expenses__camp=self.camp)) + .order_by('name')) + return context + class CredebtorCreateView( CampViewMixin, @@ -198,10 +215,28 @@ class CredebtorListView( RaisePermissionRequiredMixin, ListView, ): - model = Credebtor template_name = "credebtor_list.html" permission_required = "camps.expense_create_permission" + def get_queryset(self): + expenses=Expense.objects.filter(camp=self.camp) + revenues=Revenue.objects.filter(camp=self.camp) + return (Credebtor.objects.filter( + chain=self.chain + ).prefetch_related( + Prefetch( + 'expenses', + queryset=expenses, + to_attr="current_expenses", + ) + ).prefetch_related( + Prefetch( + 'revenues', + queryset=revenues, + to_attr="current_revenues", + ) + )) + def get_context_data(self, **kwargs): """Add chain to context.""" context = super().get_context_data(**kwargs) @@ -387,9 +422,9 @@ class ReimbursementCreateView(CampViewMixin, ExpensePermissionMixin, CreateView) def get(self, request, *args, **kwargs): """Check if this user has any approved and un-reimbursed expenses.""" if not request.user.expenses.filter( - reimbursement__isnull=True, - approved=True, - paid_by_bornhack=False, + reimbursement__isnull=True, + approved=True, + paid_by_bornhack=False, ): messages.error( request,

@@ -29,6 +29,17 @@

Notes:

{{ credebtor.notes }}

{% endif %} + +
+ +

{{ credebtor.current_expenses.count }} Expenses
+ {% include 'includes/expense_list_panel.html' with expense_list=credebtor.current_expenses %} + +
+ +
{{ credebtor.current_revenues.count }} Revenues
+ {% include 'includes/revenue_list_panel.html' with revenue_list=credebtor.current_revenues %} + Create Expense Create Revenue
IDCampInvoice Date Created By
{{ expense.pk }}{{ expense.pk }}{{ expense.pk }}{{ expense.pk }}{{ expense.camp.title }}{{ expense.invoice_date }} {{ expense.user.email }} {% if expense.reimbursement and not expense.paid_by_bornhack %} {% if request.resolver_match.app_name == "backoffice" %} - Details + Details {% else %} - Details + Details {% endif %} {% else %} N/A @@ -55,15 +61,15 @@ {% if request.resolver_match.app_name == "backoffice" %} - Details + Details {% if request.user.is_staff %} Admin {% endif %} {% else %} - Details + Details {% if not expense.approved %} - Update - Delete + Update + Delete {% endif %} {% endif %}
IDCampInvoice Date Created By Debtor
{{ revenue.pk }}{{ revenue.camp.title }}{{ revenue.invoice_date }} {{ revenue.user.email }} {{ revenue.debtor }}{{ revenue.approval_status }} {% if request.resolver_match.app_name == "backoffice" %} - Details + Details {% if request.user.is_staff %} Admin {% endif %} {% else %} - Details - Update - Delete + Details + Update + Delete {% endif %}