22from typing import Any
33
44from django .core .management .base import BaseCommand , CommandParser
5- from django .db .models import Q , Subquery
5+ from django .db .models import Q
66from shared .plan .constants import (
77 FREE_PLAN_REPRESENTATIONS ,
88 PLANS_THAT_CAN_TRIAL ,
9- TierName ,
9+ PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS ,
10+ SENTRY_PAID_USER_PLAN_REPRESENTATIONS ,
11+ PlanName ,
1012 TrialStatus ,
1113)
1214
@@ -30,12 +32,10 @@ def handle(self, *args: Any, **options: Any) -> None:
3032 stripe_customer_id = None ,
3133 ).update (trial_status = TrialStatus .NOT_STARTED .value )
3234
33- sentry_plans = Plan .objects .filter (tier = TierName .SENTRY .value )
34- pro_plans = Plan .objects .filter (tier = TierName .PRO .value , paid_plan = True )
3535 # ONGOING
3636 if trial_status_type == "all" or trial_status_type == "ongoing" :
3737 Owner .objects .filter (
38- plan__in = Subquery ( sentry_plans . values_list ( "name" , flat = True )) ,
38+ plan__in = SENTRY_PAID_USER_PLAN_REPRESENTATIONS ,
3939 trial_end_date__gt = datetime .now (),
4040 ).update (trial_status = TrialStatus .ONGOING .value )
4141
@@ -44,22 +44,22 @@ def handle(self, *args: Any, **options: Any) -> None:
4444 Owner .objects .filter (
4545 # Currently paying sentry customer with trial_end_date
4646 Q (
47- plan__in = Subquery ( sentry_plans . values_list ( "name" , flat = True )) ,
47+ plan__in = SENTRY_PAID_USER_PLAN_REPRESENTATIONS ,
4848 stripe_customer_id__isnull = False ,
4949 stripe_subscription_id__isnull = False ,
5050 trial_end_date__lte = datetime .now (),
5151 )
5252 # Currently paying sentry customer without trial_end_date
5353 | Q (
54- plan__in = Subquery ( sentry_plans . values_list ( "name" , flat = True )) ,
54+ plan__in = SENTRY_PAID_USER_PLAN_REPRESENTATIONS ,
5555 stripe_customer_id__isnull = False ,
5656 stripe_subscription_id__isnull = False ,
5757 trial_start_date__isnull = True ,
5858 trial_end_date__isnull = True ,
5959 )
6060 # Previously paid but now back to basic with trial start/end dates
6161 | Q (
62- plan = "users-basic" ,
62+ plan = PlanName . BASIC_PLAN_NAME . value ,
6363 stripe_customer_id__isnull = False ,
6464 trial_start_date__isnull = False ,
6565 trial_end_date__isnull = False ,
@@ -73,20 +73,20 @@ def handle(self, *args: Any, **options: Any) -> None:
7373 ~ Q (plan__in = PLANS_THAT_CAN_TRIAL )
7474 # Previously paid but now back to basic without trial start/end dates
7575 | Q (
76- plan = "users-basic" ,
76+ plan = PlanName . BASIC_PLAN_NAME . value ,
7777 stripe_customer_id__isnull = False ,
7878 trial_start_date__isnull = True ,
7979 trial_end_date__isnull = True ,
8080 )
8181 # Currently paying customer that isn't a sentry plan (they would be expired)
8282 | Q (
83- ~ Q (plan__in = Subquery ( sentry_plans . values_list ( "name" , flat = True )) ),
83+ ~ Q (plan__in = SENTRY_PAID_USER_PLAN_REPRESENTATIONS ),
8484 stripe_subscription_id__isnull = False ,
8585 stripe_customer_id__isnull = False ,
8686 )
8787 # Invoiced customers without stripe info
8888 | Q (
89- Q (plan__in = Subquery ( pro_plans . values_list ( "name" , flat = True )) ),
89+ Q (plan__in = PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS ),
9090 stripe_subscription_id__isnull = True ,
9191 stripe_customer_id__isnull = True ,
9292 )
0 commit comments