|
|
|
@ -27,7 +27,7 @@ from apps.course.models import Course |
|
|
|
from apps.school.models import SchoolSchedule |
|
|
|
from apps.school.models import SchoolSchedule |
|
|
|
from apps.payment.tasks import transaction_to_mixpanel, product_payment_to_mixpanel, transaction_to_roistat |
|
|
|
from apps.payment.tasks import transaction_to_mixpanel, product_payment_to_mixpanel, transaction_to_roistat |
|
|
|
|
|
|
|
|
|
|
|
from .models import AuthorBalance, CoursePayment, SchoolPayment |
|
|
|
from .models import AuthorBalance, CoursePayment, SchoolPayment, Payment |
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger('django') |
|
|
|
logger = logging.getLogger('django') |
|
|
|
|
|
|
|
|
|
|
|
@ -102,13 +102,13 @@ class SchoolBuyView(TemplateView): |
|
|
|
weekdays = set(request.GET.getlist('weekdays', [])) |
|
|
|
weekdays = set(request.GET.getlist('weekdays', [])) |
|
|
|
roistat_visit = request.COOKIES.get('roistat_visit', None) |
|
|
|
roistat_visit = request.COOKIES.get('roistat_visit', None) |
|
|
|
if not weekdays: |
|
|
|
if not weekdays: |
|
|
|
messages.error(request, 'Выберите несколько дней недели.') |
|
|
|
messages.error(request, 'Выберите дни для покупки.') |
|
|
|
return redirect('school:summer-school') |
|
|
|
return redirect('school:school') |
|
|
|
try: |
|
|
|
try: |
|
|
|
weekdays = [int(weekday) for weekday in weekdays] |
|
|
|
weekdays = [int(weekday) for weekday in weekdays] |
|
|
|
except ValueError: |
|
|
|
except ValueError: |
|
|
|
messages.error(request, 'Ошибка выбора дней недели.') |
|
|
|
messages.error(request, 'Ошибка выбора дней недели.') |
|
|
|
return redirect('school:summer-school') |
|
|
|
return redirect('school:school') |
|
|
|
prev_school_payment = SchoolPayment.objects.filter( |
|
|
|
prev_school_payment = SchoolPayment.objects.filter( |
|
|
|
user=request.user, |
|
|
|
user=request.user, |
|
|
|
date_start__lte=now().date(), |
|
|
|
date_start__lte=now().date(), |
|
|
|
@ -122,6 +122,11 @@ class SchoolBuyView(TemplateView): |
|
|
|
).first() # ??? first? |
|
|
|
).first() # ??? first? |
|
|
|
add_days = bool(prev_school_payment) |
|
|
|
add_days = bool(prev_school_payment) |
|
|
|
if add_days: |
|
|
|
if add_days: |
|
|
|
|
|
|
|
amount_data = Payment.calc_amount(user=request.user, weekdays=weekdays) |
|
|
|
|
|
|
|
if not amount_data.get('amount'): |
|
|
|
|
|
|
|
messages.error(request, 'Выбранные дни отсутствуют в оставшемся периоде подписки.') |
|
|
|
|
|
|
|
return redirect('school:school') |
|
|
|
|
|
|
|
|
|
|
|
school_payment = SchoolPayment.objects.create( |
|
|
|
school_payment = SchoolPayment.objects.create( |
|
|
|
user=request.user, |
|
|
|
user=request.user, |
|
|
|
weekdays=weekdays, |
|
|
|
weekdays=weekdays, |
|
|
|
@ -130,10 +135,10 @@ class SchoolBuyView(TemplateView): |
|
|
|
add_days=True, |
|
|
|
add_days=True, |
|
|
|
roistat_visit=roistat_visit, |
|
|
|
roistat_visit=roistat_visit, |
|
|
|
) |
|
|
|
) |
|
|
|
if school_payment.amount <= 0: |
|
|
|
|
|
|
|
messages.error(request, 'Выбранные дни отсутствуют в оставшемся периоде подписки') |
|
|
|
|
|
|
|
return redirect(reverse_lazy('school:school')) |
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
|
|
|
|
if len(weekdays) < 2: |
|
|
|
|
|
|
|
messages.error(request, 'Выберите минимум 2 дня недели.') |
|
|
|
|
|
|
|
return redirect('school:school') |
|
|
|
school_payment = SchoolPayment.objects.create( |
|
|
|
school_payment = SchoolPayment.objects.create( |
|
|
|
user=request.user, |
|
|
|
user=request.user, |
|
|
|
weekdays=weekdays, |
|
|
|
weekdays=weekdays, |
|
|
|
|