Commit 26dff5cb authored by Birin Sanchez's avatar Birin Sanchez
Browse files

forced_update: Change account_type according to subscription.


Signed-off-by: Birin Sanchez's avatarBirin Sanchez <birin.sanchez@puri.sm>
parent 01f049b0
Pipeline #12322 passed with stage
in 39 seconds
......@@ -2,7 +2,7 @@ import logging
import datetime
from django.conf import settings
from django.utils import timezone
from purist.models import get_woo_connection
from purist.models import get_woo_connection, AccountType
from purist.limitmonitor import ParserContainer
from limitmonitor.models import ExternalCredit, ExternalBundle
from limitmonitor.tunnel import TunnelManager
......@@ -56,8 +56,26 @@ def parse_subscription(json_entry):
else:
bundle_key = line_item.get('product_id')
# create result
# get account_type from subscription
line_item_meta = line_item["meta"]
for meta in line_item_meta:
if meta["key"] == "service-bundle":
acct_value = meta["value"]
break
else:
acct_value = None
account_type = AccountType.UNDEFINED
if acct_value:
acct_value = acct_value.lower()
if 'family' in acct_value:
account_type = AccountType.GROUP
elif 'complete' in acct_value:
account_type = AccountType.COMPLETE
elif 'basic' in acct_value:
account_type = AccountType.BASIC
# create result
result = {
"parser": ParserContainer.WOO_SUBSCRIPTION_V1,
"external_key": subscription_id,
......@@ -67,7 +85,8 @@ def parse_subscription(json_entry):
"quantity": 1,
"account": username,
"next_renewal": next_renewal,
"status": json_entry["status"]
"status": json_entry["status"],
"account_type": account_type
}
return result
......@@ -189,6 +208,12 @@ def forced_update(user):
ext_cred.error_message = error
ext_cred.is_converted = is_converted
ext_cred.save()
if is_converted:
# Set account_type as specified by subscription
# when conversion succeeds.
user.account_type = parsed_sub['account_type']
user.save()
# TODO: process other subscription statuses
else:
logger.info('Subscription {} for user {} status is: {}'.format(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment