From 8becc697ea36121348f01961719f03a0f9b3c591 Mon Sep 17 00:00:00 2001 From: James Kiger Date: Wed, 4 Sep 2024 14:43:01 -0400 Subject: [PATCH] Use only asr/mt instead of nlp as usage prefix --- kobo/apps/organizations/models.py | 7 ++++--- kobo/apps/organizations/types.py | 2 +- kobo/apps/stripe/constants.py | 9 +-------- kobo/apps/trackers/utils.py | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/kobo/apps/organizations/models.py b/kobo/apps/organizations/models.py index aa22e94b1b..261a2ce52a 100644 --- a/kobo/apps/organizations/models.py +++ b/kobo/apps/organizations/models.py @@ -11,7 +11,7 @@ if settings.STRIPE_ENABLED: from djstripe.models import Customer, Subscription from kobo.apps.stripe.constants import ACTIVE_STRIPE_STATUSES, ORGANIZATION_USAGE_MAX_CACHE_AGE, \ - USAGE_LIMIT_MAP_STRIPE, USAGE_LIMIT_MAP + USAGE_LIMIT_MAP from functools import partial from organizations.abstract import ( @@ -108,8 +108,9 @@ def is_organization_over_plan_limit(self, limit_type: UsageType) -> Union[bool, if not settings.STRIPE_ENABLED: return None - cached_usage = self.get_cached_usage(USAGE_LIMIT_MAP[limit_type]) - stripe_key = f'{USAGE_LIMIT_MAP_STRIPE[limit_type]}_limit' + limit_key = USAGE_LIMIT_MAP[limit_type] + cached_usage = self.get_cached_usage(limit_key) + stripe_key = limit_key + '_limit' current_limit = Organization.objects.filter( id=self.id, djstripe_customers__subscriptions__status__in=ACTIVE_STRIPE_STATUSES, diff --git a/kobo/apps/organizations/types.py b/kobo/apps/organizations/types.py index f6e2054635..e9570c319d 100644 --- a/kobo/apps/organizations/types.py +++ b/kobo/apps/organizations/types.py @@ -1,3 +1,3 @@ from typing import Literal -UsageType = Literal['character', 'seconds', 'submission', 'storage'] +UsageType = Literal['characters', 'seconds', 'submission', 'storage'] diff --git a/kobo/apps/stripe/constants.py b/kobo/apps/stripe/constants.py index 46c3d7a8d1..82e9926dfb 100644 --- a/kobo/apps/stripe/constants.py +++ b/kobo/apps/stripe/constants.py @@ -22,15 +22,8 @@ ORGANIZATION_USAGE_MAX_CACHE_AGE = timedelta(minutes=15) USAGE_LIMIT_MAP = { - 'character': 'mt_character', + 'characters': 'mt_characters', 'seconds': 'asr_seconds', 'storage': 'storage_bytes', 'submission': 'submission', } - -USAGE_LIMIT_MAP_STRIPE = { - 'character': 'nlp_character', - 'seconds': 'nlp_seconds', - 'storage': 'storage_bytes', - 'submission': 'submission', -} diff --git a/kobo/apps/trackers/utils.py b/kobo/apps/trackers/utils.py index 0f9d3176d7..e00053ca0b 100644 --- a/kobo/apps/trackers/utils.py +++ b/kobo/apps/trackers/utils.py @@ -51,7 +51,7 @@ def update_nlp_counter( if service.endswith('mt_characters'): kwargs['total_mt_characters'] = F('total_mt_characters') + amount if asset_id is not None: - PlanAddOn.increment_add_ons_for_user(user_id, 'character', amount) + PlanAddOn.increment_add_ons_for_user(user_id, 'characters', amount) NLPUsageCounter.objects.filter(pk=counter_id).update( counters=IncrementValue('counters', keyname=service, increment=amount),