Merge branch 'yandex_rebiling' into 'dev'

finance email

See merge request !313
remotes/origin/revert-6d879fe8
Andrey 8 years ago
commit c633413d1c
  1. 12
      finance/models.py
  2. 18
      finance/signals.py
  3. 2
      finance/views.py

@ -1,5 +1,6 @@
# coding=utf-8 # coding=utf-8
from django.conf import settings from django.conf import settings
from django.core.mail import EmailMessage
from django.db import models from django.db import models
from yandex_money.models import Payment from yandex_money.models import Payment
@ -64,6 +65,17 @@ class Invoice(models.Model):
return '''Вам выставлен счёт,''' if \ return '''Вам выставлен счёт,''' if \
self.comment == "" else self.comment self.comment == "" else self.comment
def send_link(self):
msg = EmailMessage(
'Вам выставлен новый счёт',
"""%s для оплаты перейдите по ссылке
%s/api/v1/finance/payment/%s/""" % (self.get_comment(), settings.DOMAIN, self.yandex_pay.id),
to=[self.yandex_pay.cps_email],
bcc=[self.bill.opener.email],
reply_to=[self.bill.opener.email],
)
msg.send()
def __str__(self): def __str__(self):
return '%s:%s %s' % (self.id, self.get_status_display(), self.bill.user) return '%s:%s %s' % (self.id, self.get_status_display(), self.bill.user)

@ -5,27 +5,11 @@ from django.dispatch import receiver
from yandex_money.models import Payment from yandex_money.models import Payment
from django.conf import settings from django.conf import settings
from finance.models import Invoice, InvoiceRebilling from finance.models import Invoice
from courses.models import Course from courses.models import Course
from progress.models import Progress, ProgressLesson from progress.models import Progress, ProgressLesson
@receiver(pre_save, sender=InvoiceRebilling)
def invoice_signal(instance, **kwargs):
"""Отправка сообщения после сохранения рассрочки"""
if instance.yandex_pay and instance.method == 'Y' and instance.status == 'P':
msg = EmailMessage(
'Вам выставлен новый счёт',
"""%s для оплаты перейдите по ссылке
%s/api/v1/finance/payment/%s/""" % (instance.get_comment(), settings.DOMAIN, instance.yandex_pay.id),
to=[instance.yandex_pay.cps_email],
bcc=[instance.bill.opener.email],
reply_to=[instance.bill.opener.email],
)
msg.send()
@receiver(pre_save, sender=Invoice) @receiver(pre_save, sender=Invoice)
def invoice_signal(instance, **kwargs): def invoice_signal(instance, **kwargs):
"""Отправка сообщения после сохранения платежа""" """Отправка сообщения после сохранения платежа"""

@ -127,7 +127,7 @@ class InvoiceDetailView(APIView):
is_open=is_open, is_open=is_open,
pay_count=pay_count, pay_count=pay_count,
) )
invoice.send_link()
else: else:
try: try:
invoice = Invoice.objects.get(id=invoice_id) invoice = Invoice.objects.get(id=invoice_id)

Loading…
Cancel
Save