From 1484750c8aad73fa7e348a29089cc2594bb40a4f Mon Sep 17 00:00:00 2001 From: Muhammad Zubair Date: Thu, 22 Jun 2023 20:26:46 +0500 Subject: [PATCH] feat: updated query to avoid enntitlements with with course run. --- .../management/commands/expire_and_create_entitlements.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/djangoapps/entitlements/management/commands/expire_and_create_entitlements.py b/common/djangoapps/entitlements/management/commands/expire_and_create_entitlements.py index c26498bbe7..1949213ce2 100644 --- a/common/djangoapps/entitlements/management/commands/expire_and_create_entitlements.py +++ b/common/djangoapps/entitlements/management/commands/expire_and_create_entitlements.py @@ -67,9 +67,12 @@ class Command(BaseCommand): expiration_period = current_date - relativedelta(years=1) exceptional_expiration_period = current_date - relativedelta(years=1, months=6) normal_entitlements = CourseEntitlement.objects.filter( - expired_at__isnull=True, created__lte=expiration_period).exclude(course_uuid__in=MIT_SUPPLY_CHAIN_COURSES) + expired_at__isnull=True,created__lte=expiration_period, + enrollment_course_run__isnull=True).exclude(course_uuid__in=MIT_SUPPLY_CHAIN_COURSES) + exceptional_entitlements = CourseEntitlement.objects.filter( - expired_at__isnull=True, created__lte=exceptional_expiration_period, course_uuid__in=MIT_SUPPLY_CHAIN_COURSES) + expired_at__isnull=True, created__lte=exceptional_expiration_period, + enrollment_course_run__isnull=True, course_uuid__in=MIT_SUPPLY_CHAIN_COURSES) entitlements = normal_entitlements | exceptional_entitlements logger.info('Total entitlements that have reached expiration period are %d ', entitlements.count())