Skip to content

Commit

Permalink
Add claimed visits and approved visits, fix budget calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
pxwxnvermx committed Oct 6, 2023
1 parent 3fbe259 commit e4554d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
15 changes: 8 additions & 7 deletions commcare_connect/opportunity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def remaining_budget(self) -> int:

@property
def claimed_budget(self):
return self.claimed_visits * self.budget_per_visit

@property
def utilised_budget(self):
return self.approved_visits * self.budget_per_visit

@property
def claimed_visits(self):
opp_access = OpportunityAccess.objects.filter(opportunity=self)
used_budget = OpportunityClaim.objects.filter(opportunity_access__in=opp_access).aggregate(
Sum("max_payments")
Expand All @@ -79,13 +87,6 @@ def claimed_budget(self):
used_budget = 0
return used_budget

@property
def utilised_budget(self):
user_visits = (
UserVisit.objects.filter(opportunity=self).exclude(status=VisitValidationStatus.over_limit).count()
)
return user_visits

@property
def approved_visits(self):
approved_user_visits = (
Expand Down
16 changes: 10 additions & 6 deletions commcare_connect/templates/opportunity/opportunity_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,32 @@ <h1 class="display-5 mb-0">{{ object.name }}</h1>
<th scope="row">Daily Visits per user</th>
<td>{{ object.daily_max_visits_per_user }}</td>
</tr>
<tr>
<th scope="row">Total Budget</th>
<td>{{ object.total_budget }}</td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-6">
<table class="table table-borderless">
<tbody>
<tr>
<th scope="row">Total Budget</th>
<td>{{ object.total_budget }}</td>
</tr>
<tr>
<th scope="row">Budget per visit</th>
<td>{{ object.budget_per_visit }}</td>
</tr>
<tr>
<th scope="row">Budget Claimed</th>
<th scope="row">Claimed Budget</th>
<td>{{ object.claimed_budget }}</td>
</tr>
<tr>
<th scope="row">Budget Utilised</th>
<th scope="row">Utilised Budget</th>
<td>{{ object.utilised_budget }}</td>
</tr>
<tr>
<th scope="row">Claimed Visits</th>
<td>{{ object.claimed_visits }}</td>
</tr>
<tr>
<th scope="row">Approved Visits</th>
<td>{{ object.approved_visits }}</td>
Expand Down

0 comments on commit e4554d7

Please sign in to comment.