Mbonea commited on
Commit
227efc1
·
1 Parent(s): dfa6f47

message issues resolved

Browse files
Files changed (1) hide show
  1. App/Users/Model.py +10 -5
App/Users/Model.py CHANGED
@@ -162,9 +162,10 @@ class User(models.Model):
162
  for promo_plan in promo_plans:
163
  plan_valid = await promo_plan.is_promo_valid()
164
  if plan_valid:
165
- Subscription.create()
 
 
166
  await new_user.activate_user()
167
- await new_user.send_plan_subscription_message(promo_plan)
168
 
169
  # Create the user in the database
170
 
@@ -179,13 +180,13 @@ class User(models.Model):
179
  logger.error(f"Error creating user: {e}")
180
  raise e
181
 
182
- async def send_plan_subscription_message(self, plan: Plan):
183
  message = self.message_templates.subscription_created_message(
184
- user_name=self.name, plan_name=plan.name
185
  )
186
  await self.send_message(message=message)
187
 
188
- async def create_subscription(self, plan: Plan):
189
  expiration_time = datetime.datetime.now() + datetime.timedelta(
190
  hours=plan.duration
191
  )
@@ -200,6 +201,10 @@ class User(models.Model):
200
  active=True,
201
  )
202
  await self.activate_user()
 
 
 
 
203
 
204
  async def send_welcome_message(self):
205
  """Sends a welcome message to the user."""
 
162
  for promo_plan in promo_plans:
163
  plan_valid = await promo_plan.is_promo_valid()
164
  if plan_valid:
165
+ await new_user.create_subscription(
166
+ plan=promo_plan, send_message=True
167
+ )
168
  await new_user.activate_user()
 
169
 
170
  # Create the user in the database
171
 
 
180
  logger.error(f"Error creating user: {e}")
181
  raise e
182
 
183
+ async def send_plan_subscription_message(self, plan: Plan, expiration_time):
184
  message = self.message_templates.subscription_created_message(
185
+ expiration_time=expiration_time, plan_name=plan.name
186
  )
187
  await self.send_message(message=message)
188
 
189
+ async def create_subscription(self, plan: Plan, send_message=False):
190
  expiration_time = datetime.datetime.now() + datetime.timedelta(
191
  hours=plan.duration
192
  )
 
201
  active=True,
202
  )
203
  await self.activate_user()
204
+ if send_message:
205
+ self.send_plan_subscription_message(
206
+ plan=plan, expiration_time=expiration_time
207
+ )
208
 
209
  async def send_welcome_message(self):
210
  """Sends a welcome message to the user."""