From 2923e7c63654e41e43c4e297fa0d060b31b9ff83 Mon Sep 17 00:00:00 2001 From: Rohan Date: Tue, 17 Dec 2024 13:56:19 +0530 Subject: [PATCH] fix: seat count calculation in plan detail resolver --- backend/backend/graphene/queries/quotas.py | 31 +++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/backend/backend/graphene/queries/quotas.py b/backend/backend/graphene/queries/quotas.py index 7b81e6f9..c1c912fd 100644 --- a/backend/backend/graphene/queries/quotas.py +++ b/backend/backend/graphene/queries/quotas.py @@ -1,5 +1,11 @@ from api.utils.access.permissions import user_is_org_member -from api.models import App, Organisation, OrganisationMember, OrganisationMemberInvite +from api.models import ( + App, + Organisation, + OrganisationMember, + OrganisationMemberInvite, + ServiceAccount, +) from backend.quotas import PLAN_CONFIG from django.utils import timezone @@ -11,13 +17,24 @@ def resolve_organisation_plan(self, info, organisation_id): plan = PLAN_CONFIG[organisation.plan] - plan["user_count"] = ( - OrganisationMember.objects.filter( + plan["seats_used"] = { + "users": ( + OrganisationMember.objects.filter( + organisation=organisation, deleted_at=None + ).count() + + OrganisationMemberInvite.objects.filter( + organisation=organisation, + valid=True, + expires_at__gte=timezone.now(), + ).count() + ), + "service_accounts": ServiceAccount.objects.filter( organisation=organisation, deleted_at=None - ).count() - + OrganisationMemberInvite.objects.filter( - organisation=organisation, valid=True, expires_at__gte=timezone.now() - ).count() + ).count(), + } + + plan["seats_used"]["total"] = ( + plan["seats_used"]["users"] + plan["seats_used"]["service_accounts"] ) plan["app_count"] = App.objects.filter(