You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.3 KiB
38 lines
1.3 KiB
from django.db.models.signals import post_save
|
|
from django.dispatch import receiver
|
|
from django.core.mail import send_mail, EmailMultiAlternatives
|
|
from django.template.loader import get_template, render_to_string
|
|
|
|
from .models import WithDraw, InvoiceHistory, Transaction
|
|
|
|
|
|
@receiver(post_save, sender=WithDraw)
|
|
def send_for_accountant(sender, instance, created, **kwargs):
|
|
|
|
if created:
|
|
ctx_dict = {
|
|
'username': instance.user.username,
|
|
}
|
|
subject, from_email, to = 'Заявка на распечатку', 'mukhtar@mukhtar', 'muhtarzubanchi05@gmail.com'
|
|
text_content = render_to_string('send_for_accountant.txt', ctx_dict)
|
|
html_content = get_template('send_for_accountant.html').render(ctx_dict)
|
|
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
|
|
msg.send()
|
|
|
|
|
|
@receiver(post_save, sender=Transaction)
|
|
def add_invoice_history(sender, instance,created, **kwargs):
|
|
if 'add' in instance.type:
|
|
inv_history = InvoiceHistory()
|
|
inv_history.comment = 'Пополнение счета'
|
|
inv_history.sum = instance.sum
|
|
inv_history.user = instance.user
|
|
inv_history.save()
|
|
|
|
|
|
@receiver(post_save, sender=Transaction)
|
|
def reserve_stages(sender, instance, created, **kwargs):
|
|
if 'reservation' in instance.type:
|
|
pass
|
|
|
|
|
|
|