Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Claim Limit Remaining Budget Fix #445

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

pxwxnvermx
Copy link
Contributor

@pxwxnvermx pxwxnvermx commented Dec 5, 2024

The remaining budget calculation for Managed Opportunities was off due to the org_pay component added to the total budget. To calculate the effective user total budget we have to remove the org_pay component from the total budget, then this user total budget can be used to calculate the remaining budget.

This PR will fix the remaining budget calculation and also fix the bug related to Opportunity Claims getting created for users in opportunities where the budget is exhausted.

Ticket

Copy link
Member

@sravfeyn sravfeyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Might be worth adding a test case for below bug

This PR will fix the remaining budget calculation and also fix the bug related to Opportunity Claims getting created for users in opportunities where the budget is exhausted.

Copy link
Collaborator

@calellowitz calellowitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels backwards. Shouldn't claimed budget account for the org pay (since we are reserving that part of the budget as well), rather than have remaining budget ignore org pay. I think the end result will be the same, but it seems more correct to say the org pay was claimed, and remaining, rather than excluding it from both

Copy link
Collaborator

@calellowitz calellowitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few questions, but the actual change looks good

def test_opportunity_stats(opportunity: Opportunity, user: User):
payment_unit_sub = PaymentUnitFactory(
payment_unit_sub = PaymentUnitFactory.create(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this change do

payment_units = [payment_unit_sub, payment_unit1, payment_unit2]
budget_per_user = sum(pu.max_total * pu.amount for pu in payment_units)
org_pay = 0
if opportunity.managed:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we know if the opportunity is managed or not in the test?

if opportunity.managed:
org_pay = opportunity.managedopportunity.org_pay_per_visit
budget_per_user += sum(pu.max_total * org_pay for pu in payment_units)
opportunity.total_budget = budget_per_user * 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we modifying the opportunity in the test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants