From 396518539506745534fdd3f2cc4a522daf76fdb9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 7 Dec 2017 17:07:08 +0300 Subject: [PATCH] create map --- finance/signals.py | 136 ++++++++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/finance/signals.py b/finance/signals.py index 59f4124..629f328 100644 --- a/finance/signals.py +++ b/finance/signals.py @@ -7,71 +7,71 @@ from finance.models import Invoice from access.models.other import Progress -# @receiver(pre_save, sender=Invoice) -# def delete_dependencies(instance, **kwargs): -# """Отправка сообщения после сохранения платежа""" -# if instance.yandex_pay and instance.method == 'Y' and instance.status == 'P': -# msg = EmailMessage( -# 'Вам выставлен новый счёт', -# '''Вам выставлен счёт, для оплаты перейдите по ссылке -# https://go.skillbox.ru/api/v1/finance/payment/%s/''' % instance.yandex_pay.id, -# 'robo@skillbox.ru', -# [instance.yandex_pay.cps_email], -# [instance.bill.opener.email], -# reply_to=[instance.bill.opener.email], -# ) -# msg.send() -# -# if instance.status == 'F': -# if instance.is_open: -# Progress.objects.get_or_create( -# course=instance.bill.course, -# user=instance.bill.user, -# active_obj=instance.bill.course.get_first(['tutorial', 'task',]) -# ) -# msg = EmailMessage( -# 'Ваш платёж прошёл успешно', -# '''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и -# ознакомиться с материалами https://go.skillbox.ru/course/%s''' -# % (instance.bill.course.title, instance.bill.course.slug), -# 'robo@skillbox.ru', -# [instance.yandex_pay.cps_email], -# cc=[instance.bill.opener.email], -# reply_to=[instance.bill.opener.email], -# ) -# else: -# msg = EmailMessage( -# 'Ваш платёж прошёл успешно', -# '''Курс "%s" был забронирован''' % instance.bill.course.title, -# 'robo@skillbox.ru', -# [instance.yandex_pay.cps_email], -# cc=[instance.bill.opener.email], -# reply_to=[instance.bill.opener.email], -# ) -# msg.send() -# -# if instance.status == 'C': -# msg = EmailMessage( -# 'Ошибка платежа!' -# """Внимание не прошёл платёж пользавателю %s, -# по курсу "%s" ID платежа: %s. Если не получается -# решить проблему самостоятельно, ответьте на это письмо, -# постарайтесь подробно описать последовательность действий, -# которая привела к ошибке""" -# % (instance.bill.user.get_full_name(), instance.bill.course.title, instance.id), -# instance.bill.opener.email, -# reply_to=["it@skillbox.ru"] -# ) -# msg.send() -# -# -# @receiver(post_save, sender=Payment) -# def access_pay(instance, **kwargs): -# if instance.status == 'success': -# instance.invoice.status = "F" -# instance.invoice.real_price = instance.shop_amount -# instance.invoice.save() -# -# if instance.status == 'fail': -# instance.invoice.status = "C" -# instance.invoice.save() +@receiver(pre_save, sender=Invoice) +def delete_dependencies(instance, **kwargs): + """Отправка сообщения после сохранения платежа""" + if instance.yandex_pay and instance.method == 'Y' and instance.status == 'P': + msg = EmailMessage( + 'Вам выставлен новый счёт', + '''Вам выставлен счёт, для оплаты перейдите по ссылке + https://go.skillbox.ru/api/v1/finance/payment/%s/''' % instance.yandex_pay.id, + 'robo@skillbox.ru', + [instance.yandex_pay.cps_email], + [instance.bill.opener.email], + reply_to=[instance.bill.opener.email], + ) + msg.send() + + if instance.status == 'F': + if instance.is_open: + Progress.objects.get_or_create( + course=instance.bill.course, + user=instance.bill.user, + active_obj=instance.bill.course.get_first(['tutorial', 'task',]) + ) + msg = EmailMessage( + 'Ваш платёж прошёл успешно', + '''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и + ознакомиться с материалами https://go.skillbox.ru/course/%s''' + % (instance.bill.course.title, instance.bill.course.slug), + 'robo@skillbox.ru', + [instance.yandex_pay.cps_email], + cc=[instance.bill.opener.email], + reply_to=[instance.bill.opener.email], + ) + else: + msg = EmailMessage( + 'Ваш платёж прошёл успешно', + '''Курс "%s" был забронирован''' % instance.bill.course.title, + 'robo@skillbox.ru', + [instance.yandex_pay.cps_email], + cc=[instance.bill.opener.email], + reply_to=[instance.bill.opener.email], + ) + msg.send() + + if instance.status == 'C': + msg = EmailMessage( + 'Ошибка платежа!' + """Внимание не прошёл платёж пользавателю %s, + по курсу "%s" ID платежа: %s. Если не получается + решить проблему самостоятельно, ответьте на это письмо, + постарайтесь подробно описать последовательность действий, + которая привела к ошибке""" + % (instance.bill.user.get_full_name(), instance.bill.course.title, instance.id), + instance.bill.opener.email, + reply_to=["it@skillbox.ru"] + ) + msg.send() + + +@receiver(post_save, sender=Payment) +def access_pay(instance, **kwargs): + if instance.status == 'success': + instance.invoice.status = "F" + instance.invoice.real_price = instance.shop_amount + instance.invoice.save() + + if instance.status == 'fail': + instance.invoice.status = "C" + instance.invoice.save()