@@ -143,7 +143,11 @@ def validate_value(self, value):
143143 return value
144144
145145 def validate (self , plan ):
146- owner = self .context ["view" ].owner
146+ current_org = self .context ["view" ].owner
147+ if current_org .account :
148+ raise serializers .ValidationError (
149+ detail = "You cannot update your plan manually, for help or changes to plan, connect with [email protected] " 150+ )
147151
148152 # Validate quantity here because we need access to whole plan object
149153 if plan ["value" ] in PAID_PLANS :
@@ -156,16 +160,19 @@ def validate(self, plan):
156160 "Quantity for paid plan must be greater than 1"
157161 )
158162
159- plan_service = PlanService (current_org = owner )
163+ plan_service = PlanService (current_org = current_org )
160164 is_org_trialing = plan_service .is_org_trialing
161165
162- if plan ["quantity" ] < owner .activated_user_count and not is_org_trialing :
166+ if (
167+ plan ["quantity" ] < current_org .activated_user_count
168+ and not is_org_trialing
169+ ):
163170 raise serializers .ValidationError (
164171 "Quantity cannot be lower than currently activated user count"
165172 )
166173 if (
167- plan ["quantity" ] == owner .plan_user_count
168- and plan ["value" ] == owner .plan
174+ plan ["quantity" ] == current_org .plan_user_count
175+ and plan ["value" ] == current_org .plan
169176 and not is_org_trialing
170177 ):
171178 raise serializers .ValidationError (
@@ -190,6 +197,9 @@ class SubscriptionDetailSerializer(serializers.Serializer):
190197 current_period_end = serializers .IntegerField ()
191198 customer = StripeCustomerSerializer ()
192199 collection_method = serializers .CharField ()
200+ tax_ids = serializers .ListField (
201+ source = "customer.tax_ids.data" , read_only = True , allow_null = True
202+ )
193203 trial_end = serializers .IntegerField ()
194204
195205
@@ -249,6 +259,10 @@ class AccountDetailsSerializer(serializers.ModelSerializer):
249259 root_organization = RootOrganizationSerializer ()
250260 schedule_detail = serializers .SerializerMethodField ()
251261 apply_cancellation_discount = serializers .BooleanField (write_only = True )
262+ activated_student_count = serializers .SerializerMethodField ()
263+ activated_user_count = serializers .SerializerMethodField ()
264+ delinquent = serializers .SerializerMethodField ()
265+ uses_invoice = serializers .SerializerMethodField ()
252266
253267 class Meta :
254268 model = Owner
@@ -258,21 +272,22 @@ class Meta:
258272 fields = read_only_fields + (
259273 "activated_student_count" ,
260274 "activated_user_count" ,
275+ "apply_cancellation_discount" ,
261276 "checkout_session_id" ,
277+ "delinquent" ,
262278 "email" ,
263279 "inactive_user_count" ,
264280 "name" ,
265281 "nb_active_private_repos" ,
266- "plan" ,
267282 "plan_auto_activate" ,
268283 "plan_provider" ,
269- "uses_invoice " ,
284+ "plan " ,
270285 "repo_total_credits" ,
271286 "root_organization" ,
272287 "schedule_detail" ,
273288 "student_count" ,
274289 "subscription_detail" ,
275- "apply_cancellation_discount " ,
290+ "uses_invoice " ,
276291 )
277292
278293 def _get_billing (self ):
@@ -292,6 +307,26 @@ def get_schedule_detail(self, owner):
292307 def get_checkout_session_id (self , _ ):
293308 return self .context .get ("checkout_session_id" )
294309
310+ def get_activated_student_count (self , owner ):
311+ if owner .account :
312+ return owner .account .activated_student_count
313+ return owner .activated_student_count
314+
315+ def get_activated_user_count (self , owner ):
316+ if owner .account :
317+ return owner .account .activated_user_count
318+ return owner .activated_user_count
319+
320+ def get_delinquent (self , owner ):
321+ if owner .account :
322+ return owner .account .is_delinquent
323+ return owner .delinquent
324+
325+ def get_uses_invoice (self , owner ):
326+ if owner .account :
327+ return owner .account .invoice_billing .filter (is_active = True ).exists ()
328+ return owner .uses_invoice
329+
295330 def update (self , instance , validated_data ):
296331 if "pretty_plan" in validated_data :
297332 desired_plan = validated_data .pop ("pretty_plan" )
0 commit comments