Skip to content

Commit

Permalink
Use only asr/mt instead of nlp as usage prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrkiger committed Sep 4, 2024
1 parent 296c2bf commit 8becc69
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
7 changes: 4 additions & 3 deletions kobo/apps/organizations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion kobo/apps/organizations/types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from typing import Literal

UsageType = Literal['character', 'seconds', 'submission', 'storage']
UsageType = Literal['characters', 'seconds', 'submission', 'storage']
9 changes: 1 addition & 8 deletions kobo/apps/stripe/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
2 changes: 1 addition & 1 deletion kobo/apps/trackers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 8becc69

Please sign in to comment.