From eb46c82ae1370d5fcc8f80e5dd799af5dc8312a4 Mon Sep 17 00:00:00 2001 From: Yingtong Li Date: Wed, 15 Jul 2020 17:03:52 +1000 Subject: [PATCH] Add withdrawn reimbursement claim state --- sstreasury/models.py | 9 +++++---- sstreasury/views.py | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sstreasury/models.py b/sstreasury/models.py index 6e2342b..02f2a01 100644 --- a/sstreasury/models.py +++ b/sstreasury/models.py @@ -209,6 +209,7 @@ class BudgetRevision(models.Model): class ClaimState(DescriptionEnum): DRAFT = 10, 'Draft' + WITHDRAWN = 15, 'Withdrawn' RESUBMIT = 20, 'Returned for redrafting' AWAIT_REVIEW = 30, 'Awaiting Treasury approval' APPROVED = 40, 'Approved by Treasury, awaiting payment' @@ -273,7 +274,7 @@ class ReimbursementClaim(models.Model): return False # Only Treasurer may edit if submitted - if self.state != ClaimState.DRAFT.value and self.state != ClaimState.RESUBMIT.value: + if self.state not in (ClaimState.DRAFT.value, ClaimState.RESUBMIT.value, ClaimState.WITHDRAWN.value): if user.groups.filter(name='Treasury').exists(): return True return False @@ -290,7 +291,7 @@ class ReimbursementClaim(models.Model): def can_submit(self, user): if not self.can_edit(user): return False - if self.state == ClaimState.DRAFT.value or self.state == ClaimState.RESUBMIT.value: + if self.state in (ClaimState.DRAFT.value, ClaimState.RESUBMIT.value, ClaimState.WITHDRAWN.value): return True return False @@ -300,7 +301,7 @@ class ReimbursementClaim(models.Model): if user != self.author and not user.groups.filter(name='Treasury').exists(): return False - if self.state == ClaimState.AWAIT_REVIEW.value or self.state == ClaimState.APPROVED.value: + if self.state in (ClaimState.AWAIT_REVIEW.value, ClaimState.APPROVED.value, ClaimState.DRAFT.value, ClaimState.RESUBMIT.value): return True return False @@ -309,7 +310,7 @@ class ReimbursementClaim(models.Model): return False if not user.groups.filter(name='Treasury').exists(): return False - if self.state == ClaimState.DRAFT.value or self.state == ClaimState.RESUBMIT.value or self.state == ClaimState.AWAIT_REVIEW.value: + if self.state in (ClaimState.DRAFT.value, ClaimState.RESUBMIT.value, ClaimState.AWAIT_REVIEW.value, ClaimState.WITHDRAWN.value): return True return False diff --git a/sstreasury/views.py b/sstreasury/views.py index 67b5a7d..2c993bf 100644 --- a/sstreasury/views.py +++ b/sstreasury/views.py @@ -459,6 +459,9 @@ def claim_list(request): for claim in models.ReimbursementClaim.objects.all(): 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]: @@ -471,7 +474,7 @@ def claim_list(request): else: group = claims_closed elif request.user.groups.filter(name='Treasury').exists(): - if state == models.ClaimState.PAID: + if state in [models.ClaimState.PAID, models.ClaimState.WITHDRAWN]: group = claims_closed else: group = claims_open @@ -641,7 +644,7 @@ def claim_action(request, claim): raise PermissionDenied with transaction.atomic(): - claim.update_state(request.user, models.ClaimState.DRAFT) + claim.update_state(request.user, models.ClaimState.WITHDRAWN) if 'Approve' in actions: if not claim.can_approve(request.user):