Tag budgets by cost centre, and allow filtering budgets by cost centre

This commit is contained in:
Yingtong Li 2023-05-01 20:53:44 +10:00
parent 4b3314a0f4
commit 8d3a7b7ed0
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
5 changed files with 37 additions and 6 deletions

View File

@ -79,9 +79,19 @@
<label class="three wide column">Contributors <span data-tooltip="To share this budget with other contributors, enter their email addresses, one per line"><i class="grey question circle icon"></i></span></label> <label class="three wide column">Contributors <span data-tooltip="To share this budget with other contributors, enter their email addresses, one per line"><i class="grey question circle icon"></i></span></label>
<textarea class="eleven wide column" rows="2" name="contributors" style="font-family: Lato,'Helvetica Neue',Arial,Helvetica,sans-serif;">{{ contributors }}</textarea> <textarea class="eleven wide column" rows="2" name="contributors" style="font-family: Lato,'Helvetica Neue',Arial,Helvetica,sans-serif;">{{ contributors }}</textarea>
</div> </div>
<div class="ui required inline grid field">
<label class="three wide column">Cost centre</label>
<div class="eleven wide column" style="padding: 0;">
<select class="ui dropdown" name="cost_centre">
{% for cost_centre in settings.BUDGET_COST_CENTRES %}
<option value="{{ cost_centre }}"{% if cost_centre == revision.cost_centre %} selected{% endif %}>{{ cost_centre }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="ui required inline grid field"> <div class="ui required inline grid field">
<label class="three wide column">Responsible committee</label> <label class="three wide column">Responsible committee</label>
<div class="eleven wide column" style="padding-left: 0; padding-right: 0;"> <div class="eleven wide column" style="padding: 0;">
<select class="ui dropdown" name="approver"> <select class="ui dropdown" name="approver">
{% for approver in settings.AVAILABLE_APPROVERS %} {% for approver in settings.AVAILABLE_APPROVERS %}
<option value="{{ approver[0] }}"{% if approver[0] == revision.approver %} selected{% endif %}>{{ approver[1][0] }}</option> <option value="{{ approver[0] }}"{% if approver[0] == revision.approver %} selected{% endif %}>{{ approver[1][0] }}</option>

View File

@ -49,7 +49,7 @@
<form class="ui form" method="GET"> <form class="ui form" method="GET">
<div class="fields"> <div class="fields">
<div class="eight wide field"> <div class="seven wide field">
<label>State</label> <label>State</label>
<select class="ui dropdown" name="state"> <select class="ui dropdown" name="state">
<option value="all"{% if request.GET.get('state', 'all') == 'all' %} selected{% endif %}>All states</option> <option value="all"{% if request.GET.get('state', 'all') == 'all' %} selected{% endif %}>All states</option>
@ -58,7 +58,16 @@
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
<div class="five wide field"> <div class="four wide field">
<label>Cost centre</label>
<select class="ui dropdown" name="cost_centre">
<option value="all"{% if request.GET.get('cost_centre', 'all') == 'all' %} selected{% endif %}>All cost centres</option>
{% for cost_centre in settings.BUDGET_COST_CENTRES %}
<option value="{{ cost_centre }}"{% if request.GET.get('cost_centre', 'all') == cost_centre %} selected{% endif %}>{{ cost_centre }}</option>
{% endfor %}
</select>
</div>
<div class="two wide field">
<label>Year</label> <label>Year</label>
<input name="year" value="{{ request.GET.get('year', '') }}"> <input name="year" value="{{ request.GET.get('year', '') }}">
</div> </div>
@ -94,11 +103,11 @@
<div style="text-align:center;padding-top:1em"> <div style="text-align:center;padding-top:1em">
<div class="ui pagination menu"> <div class="ui pagination menu">
{% if page.has_previous() %} {% if page.has_previous() %}
<a class="item" href="?page={{ page.previous_page_number() }}&state={{ request.GET.get('state', 'all') }}&year={{ request.GET.get('year', '') }}">&lsaquo; Prev</a> <a class="item" href="?page={{ page.previous_page_number() }}&state={{ request.GET.get('state', 'all') }}&cost_centre=request.GET.get('cost_centre', 'all')&year={{ request.GET.get('year', '') }}">&lsaquo; Prev</a>
{% endif %} {% endif %}
<a class="active item">Page {{ page.number }} of {{ page.paginator.num_pages }}</a> <a class="active item">Page {{ page.number }} of {{ page.paginator.num_pages }}</a>
{% if page.has_next() %} {% if page.has_next() %}
<a class="item" href="?page={{ page.next_page_number() }}&state={{ request.GET.get('state', 'all') }}&year={{ request.GET.get('year', '') }}">Next &rsaquo;</a> <a class="item" href="?page={{ page.next_page_number() }}&state={{ request.GET.get('state', 'all') }}&cost_centre=request.GET.get('cost_centre', 'all')&year={{ request.GET.get('year', '') }}">Next &rsaquo;</a>
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@ -113,6 +113,10 @@
</div> </div>
</td> </td>
</tr> </tr>
<tr>
<td>Cost centre</td>
<td>{{ revision.cost_centre }}</td>
</tr>
<tr> <tr>
<td>Responsible committee</td> <td>Responsible committee</td>
<td>{{ dict(settings.AVAILABLE_APPROVERS)[revision.approver][0] }}</td> <td>{{ dict(settings.AVAILABLE_APPROVERS)[revision.approver][0] }}</td>

View File

@ -64,11 +64,12 @@ class BudgetRevision(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
date = models.DateField() date = models.DateField()
contributors = models.ManyToManyField(User, related_name='+') contributors = models.ManyToManyField(User, related_name='+')
cost_centre = models.CharField(max_length=100)
approver = models.CharField(max_length=100)
comments = models.TextField() comments = models.TextField()
author = models.ForeignKey(User, on_delete=models.PROTECT, related_name='+') author = models.ForeignKey(User, on_delete=models.PROTECT, related_name='+')
time = models.DateTimeField() time = models.DateTimeField()
approver = models.CharField(max_length=100)
event_dt = models.DateTimeField(null=True) event_dt = models.DateTimeField(null=True)
event_attendees = models.CharField(max_length=20, null=True) event_attendees = models.CharField(max_length=20, null=True)

View File

@ -148,6 +148,11 @@ def revision_from_form(budget, revision, form):
else: else:
contributors = [] contributors = []
if form['cost_centre'] in settings.BUDGET_COST_CENTRES:
revision.cost_centre = form['cost_centre']
else:
errors.append('Cost centre is invalid')
if form['approver'] in dict(settings.AVAILABLE_APPROVERS): if form['approver'] in dict(settings.AVAILABLE_APPROVERS):
revision.approver = form['approver'] revision.approver = form['approver']
else: else:
@ -219,6 +224,8 @@ def budget_list(request):
if request.GET.get('state', 'all') != 'all' and str(revision.state) != request.GET.get('state', 'all'): if request.GET.get('state', 'all') != 'all' and str(revision.state) != request.GET.get('state', 'all'):
continue continue
if request.GET.get('cost_centre', 'all') != 'all' and revision.cost_centre != request.GET.get('cost_centre', 'all'):
continue
if request.GET.get('year', '') != '' and str(revision.time.year) != request.GET.get('year', ''): if request.GET.get('year', '') != '' and str(revision.time.year) != request.GET.get('year', ''):
continue continue