This commit is contained in:
Martin Quarda 2024-10-13 09:08:02 +02:00
parent 9e8c05d3ba
commit e1e1628caf

View File

@ -241,6 +241,7 @@ def payment_result(request):
if paid == 'PAID':
invoice.paid = True
invoice.save()
try:
racer = Racer.objects.get(invoice=invoice)
mail = EmailMessage(
subject=f"úspěšná registrace do závodu Alkátor race Dolní Čermná ({racer.first_name} {racer.last_name})",
@ -268,6 +269,25 @@ web: https://alkator.cz""",
bcc=["info@alkator.cz"],
cc=[]
)
except Racer.DoesNotExist:
mail = EmailMessage(
subject=f"úspěšně zaplacený nákup v Alkátor shopu",
body=f"""Zdravím tě Alkátore,
úspěšně si zakoupil merch na Alkátor shopu.
Na tento email není třeba odpovídat, protože je generován automaticky s přijatou platbou. V případě potřeby pište na info@alkator.cz .
ALKÁTOR TEAM
email: info@alkator.cz
tel: + 420 728 018 088
web: https://alkator.cz""",
from_email="info@alkator.cz",
to=[racer.profile.user.email, racer.email] if racer.email else [racer.profile.user.email],
bcc=["info@alkator.cz"],
cc=[]
)
return HttpResponse(status=200)
user = invoice.user
@ -278,11 +298,11 @@ web: https://alkator.cz""",
'user': user,
'invoice': invoice,
'products': InvoiceProduct.objects.filter(invoice=invoice),
'paid_date': racer.register_date + timedelta(days=1),
'paid_date': invoice.paid_date + timedelta(days=1),
}
)
template.render()
pdf_name = f"invoices/{user.profile.last_name}_{user.profile.first_name}.pdf"
pdf_name = f"invoices/{invoice.invoice_id}_{user.profile.last_name}_{user.profile.first_name}.pdf"
HTML(string=template.content).write_pdf(pdf_name)
attach = open(pdf_name, 'rb')
@ -290,7 +310,10 @@ web: https://alkator.cz""",
if not mail.send():
return HttpResponse(status=500)
elif paid == 'CANCELLED' and not user.paid:
racer.product.quantity += 1
racer.product.save()
racer.delete()
invoice.delete()
return HttpResponse(status=200)