feat: Implement PDF receipt generation and email sending for purchases

This commit is contained in:
Daniel (elordenador)
2026-03-23 08:19:14 +00:00
parent 260d8cf290
commit 328fe9f985
3 changed files with 73 additions and 0 deletions
+23
View File
@@ -1,9 +1,11 @@
from celery import shared_task
from django.conf import settings
from django.template.loader import render_to_string
from django.core.mail import EmailMessage
from .utilities import send_email, send_hemail
from .vars import login_message, verify_message
import random, string
from . import pdf
from .models import User, VerificationCode
@shared_task
@@ -51,3 +53,24 @@ def enviar_correo_recuperacion(email: str):
)
send_hemail(email, "Reset de Contraseña", html_content, "Estas reseteando la contraseña...")
# Purchased items should be a list of dictionary, the dictionary must follow this tags: amount, product name, price (each)
@shared_task
def process_purchase(user_id: int, purchased_items: list, payment_method: str):
user = User.objects.get(id=user_id)
total = 0
for i in purchased_items:
total += i["price"]*i["amount"]
pdf_data = pdf.generar_recibo(user.get_full_name(), total, purchased_items, payment_method)
email = EmailMessage(
subject="Tu recibo de compra",
body = "Hola, adjunto encontrarás el recibo de tu reciente transacción",
from_email = settings.DEFAULT_FROM_EMAIL,
to = [user.email]
)
email.attach("recibo.pdf", pdf_data, "application/pdf")
email.send()