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 authored and RulaKhaled committed Jan 20, 2025
1 parent 5050704 commit 40abd2d
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 @@ -149,7 +148,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(
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 @@ -214,7 +215,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
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 @@ -479,11 +477,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(
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:
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:
return True

return bool(is_same_term and is_same_seats)
Expand Down Expand Up @@ -800,7 +802,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(
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 40abd2d

Please sign in to comment.