1.1.3 autoextension and autofinish subscribes
This commit is contained in:
@@ -56,7 +56,10 @@ class SubscribeOrder(BaseModel):
|
||||
self.enable = False
|
||||
self.save()
|
||||
|
||||
subscribe_for_user.activate()
|
||||
subscribe_for_user.activate(
|
||||
paid_period_from_DT=datetime.now(),
|
||||
paid_period_to_DT=datetime.now() + timedelta(hours=self.subscribe.period)
|
||||
)
|
||||
|
||||
return self
|
||||
|
||||
|
||||
0
GeneralApp/management/__init__.py
Normal file
0
GeneralApp/management/__init__.py
Normal file
0
GeneralApp/management/commands/__init__.py
Normal file
0
GeneralApp/management/commands/__init__.py
Normal file
31
GeneralApp/management/commands/every_day_start.py
Normal file
31
GeneralApp/management/commands/every_day_start.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from datetime import datetime
|
||||
from BaseModels.mailSender import techSendMail
|
||||
from GeneralApp.funcs_options import get_options_by_opt_types, get_mail_send_options
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
mail_sets = get_mail_send_options()
|
||||
|
||||
log = ''
|
||||
log_begin_DT = datetime.now()
|
||||
msg = str(log_begin_DT)
|
||||
print('-------------')
|
||||
print(msg)
|
||||
|
||||
try:
|
||||
from SubscribesApp.funcs import finish_user_subscribes, extension_free_subscribes
|
||||
extension_free_subscribes()
|
||||
finish_user_subscribes()
|
||||
except Exception as e:
|
||||
msg = f'every_day_start fail = {str(e)}'
|
||||
print(msg)
|
||||
techSendMail(mail_sets, msg, title='every_day_start fail')
|
||||
|
||||
# if msg:
|
||||
# techSendMail(mail_sets, str(msg), title='every_1hour_start get_competitors_prices')
|
||||
|
||||
print(f'- processing time = {str(datetime.now() - log_begin_DT)} -')
|
||||
|
||||
|
||||
@@ -4,6 +4,38 @@ from django.utils.translation import get_language, activate
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
|
||||
|
||||
def extension_free_subscribes():
|
||||
subscribe = get_null_price_subscribe()
|
||||
if not subscribe:
|
||||
return None
|
||||
|
||||
user_subscribes = SubscribeForUser.objects.filter(
|
||||
enable=True,
|
||||
subscribe=subscribe
|
||||
)
|
||||
for user_subscribe in user_subscribes:
|
||||
user_subscribe.extension()
|
||||
msg = f'{str(user_subscribe)} free subscribe extended'
|
||||
print(msg)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def finish_user_subscribes():
|
||||
|
||||
finished_user_subscribes = SubscribeForUser.objects.filter(
|
||||
enable=True, paid_period_to_DT__lt=datetime.now()
|
||||
)
|
||||
finished_user_subscribes.update(enable=False)
|
||||
for finished_user_subscribe in finished_user_subscribes:
|
||||
msg = f'{str(finished_user_subscribe)} subscribe finished and switch to free'
|
||||
print(msg)
|
||||
subscribe_user_to_null_price_subscribe(finished_user_subscribe.user)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def create_subscribe_by_data(create_kwargs):
|
||||
subscribe = create_kwargs['subscribe']
|
||||
create_kwargs.update({
|
||||
|
||||
@@ -2,7 +2,7 @@ from django.db import models
|
||||
from BaseModels.base_models import BaseModel
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from colorfield.fields import ColorField
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
# options_list 29.05.2024
|
||||
# СМС уведомления
|
||||
@@ -80,9 +80,28 @@ class SubscribeForUser(BaseModel):
|
||||
res += f' {str(self.id)}'
|
||||
return res
|
||||
|
||||
def activate(self):
|
||||
def get_days_to_finish(self):
|
||||
days = (self.paid_period_to_DT - datetime.now()).days
|
||||
return days
|
||||
|
||||
def extension(self, order=None):
|
||||
if not order and self.subscribe.price > 0:
|
||||
return {'error': 'not paid'}
|
||||
|
||||
if self.subscribe.price == 0:
|
||||
self.activate(
|
||||
paid_period_from_DT=datetime.now(),
|
||||
paid_period_to_DT=datetime.now() + timedelta(hours=self.subscribe.period)
|
||||
)
|
||||
|
||||
|
||||
def activate(self, paid_period_from_DT=None, paid_period_to_DT=None):
|
||||
self.enable = True
|
||||
self.save(update_fields=['enable'])
|
||||
if paid_period_from_DT:
|
||||
self.paid_period_from_DT = paid_period_from_DT
|
||||
if paid_period_to_DT:
|
||||
self.paid_period_to_DT = paid_period_to_DT
|
||||
self.save()
|
||||
|
||||
subscribes_for_user = SubscribeForUser.objects.filter(
|
||||
user=self.user
|
||||
|
||||
Reference in New Issue
Block a user