From 2b2564257ef76406556b1d11f35c52a80f93d159 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Wed, 30 Oct 2024 11:05:31 -0700 Subject: [PATCH] Handle subscription case where it's set to trial, but renewal_date is not set. set the renewal_date for LENGTH_OF_FREE_TRIAL days from subscription creation. --- src/khoj/database/adapters/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/khoj/database/adapters/__init__.py b/src/khoj/database/adapters/__init__.py index 6de89f9f..f2fb5c0e 100644 --- a/src/khoj/database/adapters/__init__.py +++ b/src/khoj/database/adapters/__init__.py @@ -301,6 +301,11 @@ def subscription_to_state(subscription: Subscription) -> str: return SubscriptionState.INVALID.value elif subscription.type == Subscription.Type.TRIAL: # Check if the trial has expired + if not subscription.renewal_date: + # If the renewal date is not set, set it to the current date + trial length and evaluate + subscription.renewal_date = subscription.created_at + timedelta(days=LENGTH_OF_FREE_TRIAL) + subscription.save() + if subscription.renewal_date and datetime.now(tz=timezone.utc) > subscription.renewal_date: return SubscriptionState.EXPIRED.value return SubscriptionState.TRIAL.value