diff --git a/finance/views.py b/finance/views.py index 3c03ac0..1656baa 100644 --- a/finance/views.py +++ b/finance/views.py @@ -71,6 +71,21 @@ class BillListView(APIView): invoice.yandex_pay = yandex_pay invoice.save() + msg = EmailMessage( + 'Выставден новый счёт.', + '''Менеджер %s выставил счёт пользователю %s на курс "%s".''' + % ( + invoice.bill.opener.full_name(), + invoice.bill.user.email, + Course.objects.get(invoice.bill.course_token).title, + ), + 'robo@skillbox.ru', + [invoice.bill.opener.email], + bcc=['dmitry.dolya@skillbox.ru'], + ) + + msg.send() + invoices = [j for j in invoices if not j.id == invoice.id] [i.delete() for i in invoices] @@ -159,6 +174,17 @@ class YandexPay(APIView): 'shopFailURL': settings.YANDEX_MONEY_FAIL_URL, }) + msg = EmailMessage( + 'Пользователь перешёл на страницу оплаты.', + '''Пользователь "%s", переводит %s рублей.''' + % (pay.invoice.bill.user.email, str(pay.invoice.real_price)), + 'robo@skillbox.ru', + [pay.invoice.bill.opener.email], + bcc=['dmitry.dolya@skillbox.ru'], + ) + + msg.send() + return redirect(r.url) except Payment.DoesNotExist: @@ -177,8 +203,8 @@ def get_invoices(request): file_name = file_name + "__to_%s" % date_to if date_to else file_name invoices = Invoice.objects.filter(method="Y", status="F") - invoices = invoices.filter(date__lt=date_to) if date_to else invoices - invoices = invoices.filter(date__gte=date_from) if date_from else invoices + invoices = invoices.filter(yandex_pay__performed_datetime__lt=date_to) if date_to else invoices + invoices = invoices.filter(yandex_pay__performed_datetime__gte=date_from) if date_from else invoices response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="%s.csv"' % file_name @@ -189,8 +215,8 @@ def get_invoices(request): for i in invoices.order_by('-date'): course_api = CourseParamsApi(i.bill.course_token) writer.writerow([ - i.date.date(), - i.date.time(), + i.yandex_pay.performed_datetime.date(), + i.yandex_pay.performed_datetime.time(), i.bill.user.email, i.bill.user.get_full_name(), course_api.get_slug_and_title()['title'], @@ -246,17 +272,6 @@ class YandexCheckView(APIView): logger_yandex.info(xml_res) - msg = EmailMessage( - 'Списание средств с карты пользователя.', - '''Пользователь "%s", переволит %s рублей. Номер платежа в яндекс кассе %s''' - % (pay.invoice.bill.user.email, str(pay.invoice.real_price), str(data['invoiceId'])), - 'robo@skillbox.ru', - [pay.invoice.bill.opener.email], - bcc=['dmitry.dolya@skillbox.ru'], - ) - - msg.send() - return HttpResponse(xml_res, content_type='application/xml')