Implement basic filtering of claims/budgets

This commit is contained in:
Yingtong Li 2023-05-01 20:18:56 +10:00
parent 8a3a09d8ab
commit 1217770900
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 99 additions and 14 deletions

View File

@ -2,7 +2,8 @@
{#
Society Self-Service
Copyright © 2018–2020 Yingtong Li (RunasSudo)
Copyright © 2018–2023 Yingtong Li (RunasSudo)
Copyright © 2023 MUMUS Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
@ -28,7 +29,7 @@
<th class="four wide">Status</th>
<th class="one wide">View</th>
</tr>
</thead>
</thea d>
<tbody>
{% for revision in budgets %}
<tr>
@ -46,8 +47,30 @@
{% block maincontent %}
<h1>Your budgets</h1>
<form class="ui form" method="GET">
<div class="fields">
<div class="eight wide field">
<label>State</label>
<select class="ui dropdown" name="state">
<option value="all"{% if request.GET.get('state', 'all') == 'all' %} selected{% endif %}>All states</option>
{% for state in import('sstreasury.models').BudgetState %}
<option value="{{ state._value_ }}"{% if request.GET.get('state', 'all') == state._value_|string %} selected{% endif %}>{{ state.description }}</option>
{% endfor %}
</select>
</div>
<div class="five wide field">
<label>Year</label>
<input name="year" value="{{ request.GET.get('year', '') }}">
</div>
<div class="three wide field">
<label>&nbsp;</label>
<button type="submit" class="ui primary labeled icon button" style="width:100%"><i class="filter icon"></i>Filter</button>
</div>
</div>
</form>
{% if not budgets_action and not budgets_open and not budgets_closed %}
<p>You have no budgets to view. To create a budget, click <a href="{{ url('budget_new') }}">Create new budget</a>.</p>
<p>There are no budgets matching the selected criteria. To create a budget, click <a href="{{ url('budget_new') }}">Create new budget</a>.</p>
{% endif %}
{% if budgets_action %}
@ -72,3 +95,11 @@
{% block head %}
{{ super() }}
{% endblock %}
{% block script %}
{{ super() }}
<script>
$('.ui.dropdown').dropdown();
</script>
{% endblock %}

View File

@ -2,7 +2,8 @@
{#
Society Self-Service
Copyright © 2018–2020 Yingtong Li (RunasSudo)
Copyright © 2018–2023 Yingtong Li (RunasSudo)
Copyright © 2023 MUMUS Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
@ -46,8 +47,30 @@
{% block maincontent %}
<h1>Your reimbursement claims</h1>
<form class="ui form" method="GET">
<div class="fields">
<div class="eight wide field">
<label>State</label>
<select class="ui dropdown" name="state">
<option value="all"{% if request.GET.get('state', 'all') == 'all' %} selected{% endif %}>All states</option>
{% for state in import('sstreasury.models').ClaimState %}
<option value="{{ state._value_ }}"{% if request.GET.get('state', 'all') == state._value_|string %} selected{% endif %}>{{ state.description }}</option>
{% endfor %}
</select>
</div>
<div class="five wide field">
<label>Year</label>
<input name="year" value="{{ request.GET.get('year', '') }}">
</div>
<div class="three wide field">
<label>&nbsp;</label>
<button type="submit" class="ui primary labeled icon button" style="width:100%"><i class="filter icon"></i>Filter</button>
</div>
</div>
</form>
{% if not claims_action and not claims_open and not claims_closed %}
<p>You have no reimbursement claims to view. To create a claim, click <a href="{{ url('claim_new') }}">Create new claim</a>.</p>
<p>There are no reimbursement claims matching the selected criteria. To create a claim, click <a href="{{ url('claim_new') }}">Create new claim</a>.</p>
{% endif %}
{% if claims_action %}
@ -72,3 +95,11 @@
{% block head %}
{{ super() }}
{% endblock %}
{% block script %}
{{ super() }}
<script>
$('.ui.dropdown').dropdown();
</script>
{% endblock %}

View File

@ -209,17 +209,29 @@ def index(request):
@login_required
def budget_list(request):
# Filter budgets
budgets_filtered = []
for budget in models.Budget.objects.all():
revision = budget.budgetrevision_set.reverse()[0]
if not revision.can_view(request.user):
continue
if request.GET.get('state', 'all') != 'all' and str(revision.state) != request.GET.get('state', 'all'):
continue
if request.GET.get('year', '') != '' and str(revision.time.year) != request.GET.get('year', ''):
continue
budgets_filtered.append(revision)
# Categorise budgets
budgets_action = []
budgets_open = []
budgets_closed = []
for budget in models.Budget.objects.all():
revision = budget.budgetrevision_set.reverse()[0]
for revision in budgets_filtered:
state = models.BudgetState(revision.state)
if not revision.can_view(request.user):
continue
group = None
if request.user.groups.filter(name='Treasury').exists() and state == models.BudgetState.AWAIT_REVIEW:
@ -548,16 +560,27 @@ def budget_action(request, budget, revision):
@login_required
def claim_list(request):
# Filter claims
claims_filter = []
for claim in models.ReimbursementClaim.objects.all():
if not claim.can_view(request.user):
continue
if request.GET.get('state', 'all') != 'all' and str(claim.state) != request.GET.get('state', 'all'):
continue
if request.GET.get('year', '') != '' and str(claim.time.year) != request.GET.get('year', ''):
continue
claims_filter.append(claim)
# Categorise claims
claims_action = []
claims_open = []
claims_closed = []
for claim in models.ReimbursementClaim.objects.all():
for claim in claims_filter:
state = models.ClaimState(claim.state)
if not claim.can_view(request.user):
continue
group = None
if request.user.groups.filter(name='Treasury').exists() and state in [models.ClaimState.AWAIT_REVIEW, models.ClaimState.APPROVED]: