Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: Use only asr/mt instead of nlp as usage prefix #5095

Draft
wants to merge 1 commit into
base: TASK-1015-normalize-usage-naming
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading