Commit 07ccebf5 authored by Birin Sanchez's avatar Birin Sanchez
Browse files

Adds a celery task to process subscription renewals. It will only act

on subscriptions that are active using forced_updated on those users.
Signed-off-by: Birin Sanchez's avatarBirin Sanchez <>
parent 02d2b829
Pipeline #13863 passed with stage
in 38 seconds
......@@ -5,7 +5,7 @@ from django.utils import timezone
from django.contrib.auth.hashers import make_password
from purist.models import get_woo_connection, AccountType
from purist.limitmonitor import ParserContainer, ServicesContainer
from limitmonitor.models import ExternalCredit, ExternalBundle
from limitmonitor.models import ExternalCredit, ExternalBundle, Limit
from limitmonitor.tunnel import TunnelManager
logger = logging.getLogger(__name__)
......@@ -163,8 +163,10 @@ def forced_update(user):
parsed_sub = parse_subscription(sub)
if parsed_sub['bundle_key'] not in settings.WOOSUB1_PRODUCT_LIST:'Subscription {} does not belong '
'to Librem One'.format(parsed_sub['bundle_key']))'Subscription {} for user {} does not belong '
'to {}'.format(parsed_sub['bundle_key'],
continue # Skip this subscription as is not a product we care of
ext_cred = subscription_was_processed(parsed_sub, overwrite=True)
......@@ -264,3 +266,36 @@ def delete_account(user, purge_n=0, purge=False):
ldap_user = user.get_ldap()
def get_users_expired_subs(date_limit=None):
"""Returns the list of users for which the service renewal_date is
older than date_limit. If date_limit is not specified will be used. It will omit invited users, inactive
users and users created with magic carts.
magic_carts = [0, 999, 5000, 5999]
if date_limit is None:
limit =
limit = date_limit
limits = Limit.objects.filter(renewal_date__lte=limit)
users = []
for limit in limits:
user = limit.user
if hasattr(user, 'chosenreward'):
is_magic = user.chosenreward.reward in magic_carts
is_magic = False
if (
user not in users and user.is_active
and user.account_type != AccountType.INVITED
and not is_magic
return users
......@@ -2,7 +2,8 @@ from django.conf import settings
from celery.utils.log import get_task_logger
from cart.models import ChosenReward
from limitmonitor.common import parse_subscription, get_user_subscriptions, \
subscription_was_processed, get_services_from_bundle
subscription_was_processed, get_services_from_bundle, forced_update, \
logger = get_task_logger(__name__)
......@@ -69,3 +70,10 @@ def process_pending_registrations():
for reg in pending_regs:
def process_renewals():
expired_users = get_users_expired_subs()
for user in expired_users:
......@@ -38,3 +38,8 @@ def purge_users_pending_cart_task():
def process_pending_registrations():
def process_renewals():
Markdown is supported
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