From 3fbe259394d713f6bd884d07e4477bfa575a52ed Mon Sep 17 00:00:00 2001 From: Pawan Verma Date: Fri, 6 Oct 2023 16:18:24 +0530 Subject: [PATCH] Add approved_visits to opportunity detail --- commcare_connect/opportunity/models.py | 9 +++++++++ .../templates/opportunity/opportunity_detail.html | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/commcare_connect/opportunity/models.py b/commcare_connect/opportunity/models.py index e26d7872..4b4f7f01 100644 --- a/commcare_connect/opportunity/models.py +++ b/commcare_connect/opportunity/models.py @@ -86,6 +86,15 @@ def utilised_budget(self): ) return user_visits + @property + def approved_visits(self): + approved_user_visits = ( + UserVisit.objects.filter(opportunity=self, status=VisitValidationStatus.approved) + .exclude(status=VisitValidationStatus.over_limit) + .count() + ) + return approved_user_visits + class DeliverForm(models.Model): app = models.ForeignKey( diff --git a/commcare_connect/templates/opportunity/opportunity_detail.html b/commcare_connect/templates/opportunity/opportunity_detail.html index ebc874b9..f79a3d32 100644 --- a/commcare_connect/templates/opportunity/opportunity_detail.html +++ b/commcare_connect/templates/opportunity/opportunity_detail.html @@ -128,6 +128,10 @@

{{ object.name }}

Budget Utilised {{ object.utilised_budget }} + + Approved Visits + {{ object.approved_visits }} +