Skip to content

Commit

Permalink
changed no of user calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
hemant10yadav committed Oct 30, 2024
1 parent 7213dea commit d38a8e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions commcare_connect/opportunity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,16 @@ def approved_visits(self):

@property
def number_of_users(self):
return self.total_budget / self.budget_per_user
if not self.managed:
return self.total_budget / self.budget_per_user

budget_per_user = 0
payment_units = self.paymentunit_set.all()
org_pay = self.managedopportunity.org_pay_per_visit
for pu in payment_units:
budget_per_user += pu.max_total * (pu.amount + org_pay)

return self.total_budget / budget_per_user

@property
def allotted_visits(self):
Expand All @@ -181,9 +190,8 @@ def budget_per_visit_new(self):
def budget_per_user(self):
payment_units = self.paymentunit_set.all()
budget = 0
org_pay = self.managedopportunity.org_pay_per_visit if self.managed else 0
for pu in payment_units:
budget += pu.max_total * (pu.amount + org_pay)
budget += pu.max_total * pu.amount
return budget

@property
Expand Down
4 changes: 2 additions & 2 deletions commcare_connect/program/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
@pytest.mark.django_db
def test_managed_opportunity_stats():
opportunity = ManagedOpportunityFactory(total_budget=3600000, org_pay_per_visit=450)
PaymentUnitFactory(opportunity=opportunity, max_total=600, max_daily=5, amount=750, parent_payment_unit=None)
PaymentUnitFactory(opportunity=opportunity, max_total=600, max_daily=5, amount=750)

opportunity = ManagedOpportunity.objects.get(id=opportunity.id)

assert opportunity.budget_per_user == 720000
assert opportunity.budget_per_user == 450000
assert opportunity.allotted_visits == 3000
assert opportunity.number_of_users == 5
assert opportunity.max_visits_per_user_new == 600
Expand Down

0 comments on commit d38a8e1

Please sign in to comment.