-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
There was a problem hiding this 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
There was a problem hiding this 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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not change anything about how these mock objects are created. Adding the create
resolved some of the type errors I was getting in my editor.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we have that information available, this line on the top of this test function creates 1 case with a normal opportunity and another with a managed opportunity.
@pytest.mark.parametrize("opportunity", [{}, {"opp_options": {"managed": True}}], indirect=True)
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to update the opportunity budget based on the Payment Units created earlier in the test and the org_pay_per_visit
in case of a managed opportunity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like there should be a nicer way to do this, but seems fine
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