Skip to content

Commit

Permalink
a few more references for PAID and TEAM_PLANS
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-sentry committed Jan 15, 2025
1 parent b77f1b7 commit 7abf400
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 4 additions & 3 deletions api/internal/owner/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from rest_framework import serializers
from rest_framework.exceptions import PermissionDenied
from shared.plan.constants import (
PAID_PLANS,
TEAM_PLAN_MAX_USERS,
TierName,
)
Expand Down Expand Up @@ -143,7 +142,9 @@ def validate(self, plan: Dict[str, Any]) -> Dict[str, Any]:
)

# Validate quantity here because we need access to whole plan object
if plan["value"] in PAID_PLANS:
if plan["value"] in Plan.objects.filter(

Check warning on line 145 in api/internal/owner/serializers.py

View check run for this annotation

Codecov Notifications / codecov/patch

api/internal/owner/serializers.py#L145

Added line #L145 was not covered by tests
paid_plan=True, is_active=True
).values_list("name", flat=True):
if "quantity" not in plan:
raise serializers.ValidationError(
"Field 'quantity' required for updating to paid plans"
Expand Down Expand Up @@ -208,7 +209,7 @@ def get_plan(self, phase: Dict[str, Any]) -> str:
plan_name = list(stripe_plan_dict.keys())[
list(stripe_plan_dict.values()).index(plan_id)
]
marketing_plan_name = PAID_PLANS[plan_name].billing_rate
marketing_plan_name = Plan.objects.get(name=plan_name).marketing_name

Check warning on line 212 in api/internal/owner/serializers.py

View check run for this annotation

Codecov Notifications / codecov/patch

api/internal/owner/serializers.py#L212

Added line #L212 was not covered by tests
return marketing_plan_name

def get_quantity(self, phase: Dict[str, Any]) -> int:
Expand Down
14 changes: 9 additions & 5 deletions services/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from dateutil.relativedelta import relativedelta
from django.conf import settings
from shared.plan.constants import (
PAID_PLANS,
TEAM_PLANS,
PlanBillingRate,
)
from shared.plan.service import PlanService
Expand Down Expand Up @@ -475,11 +473,15 @@ def _is_similar_plan(self, owner: Owner, desired_plan: dict) -> bool:
owner.plan_user_count and owner.plan_user_count == desired_plan["quantity"]
)

team_plans = Plan.objects.filter(

Check warning on line 476 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L476

Added line #L476 was not covered by tests
tier=TierName.TEAM.value, is_active=True
).values_list("name", flat=True)

# If from PRO to TEAM, then not a similar plan
if owner.plan not in TEAM_PLANS and desired_plan["value"] in TEAM_PLANS:
if owner.plan not in team_plans and desired_plan["value"] in team_plans:

Check warning on line 481 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L481

Added line #L481 was not covered by tests
return False
# If from TEAM to PRO, then considered a similar plan but really is an upgrade
elif owner.plan in TEAM_PLANS and desired_plan["value"] not in TEAM_PLANS:
elif owner.plan in team_plans and desired_plan["value"] not in team_plans:

Check warning on line 484 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L484

Added line #L484 was not covered by tests
return True

return bool(is_same_term and is_same_seats)
Expand Down Expand Up @@ -743,7 +745,9 @@ def update_plan(self, owner, desired_plan):
else:
plan_service = PlanService(current_org=owner)
plan_service.set_default_plan_data()
elif desired_plan["value"] in PAID_PLANS:
elif desired_plan["value"] in Plan.objects.filter(

Check warning on line 748 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L748

Added line #L748 was not covered by tests
paid_plan=True, is_active=True
).values_list("name", flat=True):
if owner.stripe_subscription_id is not None:
self.payment_service.modify_subscription(owner, desired_plan)
else:
Expand Down

0 comments on commit 7abf400

Please sign in to comment.