(self, request, *args, **kwargs)
| 1001 | ) |
| 1002 | @action(detail=True, methods=["post"], url_path="delete") |
| 1003 | def delete(self, request, *args, **kwargs): |
| 1004 | organization = self.request.organization |
| 1005 | now = now_utc() |
| 1006 | plan_version = self.get_object() |
| 1007 | num_active_subscriptions = ( |
| 1008 | SubscriptionRecord.objects.active() |
| 1009 | .filter( |
| 1010 | organization=organization, |
| 1011 | billing_plan=plan_version, |
| 1012 | ) |
| 1013 | .count() |
| 1014 | ) |
| 1015 | if num_active_subscriptions > 0: |
| 1016 | raise InvalidOperation( |
| 1017 | "Cannot delete plan version with active subscriptions" |
| 1018 | ) |
| 1019 | plan_version.deleted = now |
| 1020 | plan_version.save() |
| 1021 | return Response( |
| 1022 | { |
| 1023 | "success": True, |
| 1024 | "message": f"Deleted plan version {str(plan_version)}", |
| 1025 | }, |
| 1026 | status=status.HTTP_200_OK, |
| 1027 | ) |
| 1028 | |
| 1029 | @extend_schema( |
| 1030 | parameters=None, |
nothing calls this directly
no test coverage detected