-
{% if item.action == import('sstreasury.models').BudgetAction.CREATE.value %}
-
{{ item.author.first_name }} {{ item.author.last_name }} created the budget
(view)
+
{{ item.author.first_name }} {{ item.author.last_name }} created the budget
(view)
{% elif item.action == import('sstreasury.models').BudgetAction.EDIT.value %}
-
{{ item.author.first_name }} {{ item.author.last_name }} edited the budget
(view)
+
{{ item.author.first_name }} {{ item.author.last_name }} edited the budget
(view)
{% elif item.action == import('sstreasury.models').BudgetAction.UPDATE_STATE.value %}
-
{{ item.author.first_name }} {{ item.author.last_name }} changed the state to: {{ item.get_state_display() }}
(view)
+
{{ item.author.first_name }} {{ item.author.last_name }} changed the state to: {{ item.get_state_display() }}
(view)
+ {% elif item.action == import('sstreasury.models').BudgetAction.AUTO_APPROVE.value %}
+ System changed the state to: {{ item.get_state_display() }}
(view)
{% else %}
-
{{ item.author.first_name }} {{ item.author.last_name }} modified the budget
(view)
+
{{ item.author.first_name }} {{ item.author.last_name }} modified the budget
(view)
{% endif %}
{{ localtime(item.time) }}
@@ -253,78 +254,82 @@
{% endif %}
{% endfor %}
+ {% endif %}
+
+ {% if revision.state == import('sstreasury.models').BudgetState.ENDORSED.value %}
+
Committee voting
- {% if revision.state == import('sstreasury.models').BudgetState.ENDORSED.value %}
-
Committee voting
-
-
- {% endif %}
+
{{ dict(settings.AVAILABLE_APPROVERS)[revision.approver][1] }} votes in favour are required for approval.
+
+ {% endif %}
+
+ {% if is_latest %}
{% if claims is not none %}
Reimbursement claims
diff --git a/sstreasury/models.py b/sstreasury/models.py
index 8b7a5ef..3ab704d 100644
--- a/sstreasury/models.py
+++ b/sstreasury/models.py
@@ -57,6 +57,7 @@ class BudgetAction(DescriptionEnum):
CREATE = 5, 'Created'
EDIT = 10, 'Edited'
UPDATE_STATE = 20, 'Updated state'
+ AUTO_APPROVE = 30, 'Automatically approved'
class BudgetRevision(models.Model):
budget = models.ForeignKey(Budget, on_delete=models.CASCADE)
diff --git a/sstreasury/views.py b/sstreasury/views.py
index e6b3e92..7f4ffdf 100644
--- a/sstreasury/views.py
+++ b/sstreasury/views.py
@@ -508,7 +508,27 @@ def budget_action(request, budget, revision):
vote.vote_type = vote_type.value
vote.save()
- # TODO: Check for vote threshold
+ # Check if threshold for automatic approval is reached
+ votes_in_favour = revision.budgetvote_set.filter(is_current=True, vote_type=models.BudgetVoteType.IN_FAVOUR.value).count()
+ if votes_in_favour >= dict(settings.AVAILABLE_APPROVERS)[revision.approver][1]:
+ # Automatically approve
+ revision.copy()
+ revision.time = timezone.now()
+ revision.state = models.BudgetState.APPROVED.value
+ revision.action = models.BudgetAction.AUTO_APPROVE.value
+ revision.save()
+
+ # Send emails
+ users_to_email = set()
+
+ for user in revision.contributors.all():
+ users_to_email.add(user.email)
+ for user in User.objects.filter(groups__name=revision.approver):
+ users_to_email.add(user.email)
+
+ emailer = Emailer()
+ for email in users_to_email:
+ emailer.send_mail([email], 'Budget approved: {} (BU-{})'.format(revision.name, budget.id), 'sstreasury/email/budget_approved.md', {'revision': revision})
return redirect(reverse('budget_view', kwargs={'id': budget.id}))