Skip to content

Commit

Permalink
update utilisation calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
calellowitz committed Dec 15, 2024
1 parent 3501703 commit e30bbcd
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions commcare_connect/opportunity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,10 @@ def claimed_budget(self):

@property
def utilised_budget(self):
completed_works = CompletedWork.objects.filter(opportunity_access__opportunity=self)
payment_unit_counts = completed_works.values("payment_unit").annotate(
completed_count=Count("id"), amount=F("payment_unit__amount")
)
users = OpportunityAccess.objects.filter(opportunity=self)
utilised = 0
for payment_unit_count in payment_unit_counts:
completed_count = payment_unit_count["completed_count"]
amount = payment_unit_count["amount"]
utilised += completed_count * amount
for u in users:
utilised += u.payment_accrued
return utilised

@property
Expand Down

0 comments on commit e30bbcd

Please sign in to comment.