From ebab304b753bd474b20acaa8ad915322d7e06ee7 Mon Sep 17 00:00:00 2001 From: David Bruno Vontor Date: Fri, 21 Nov 2025 15:15:47 +0100 Subject: [PATCH] Add carrier field to Refund model and update Stripe views Introduces a OneToOneField for carrier in the Refund model to support future integration and refactoring. Adds and updates TODO comments for email template usage, error handling in Stripe webhooks, and clarifies logic placement in Stripe models. --- backend/account/tasks.py | 1 + backend/commerce/models.py | 10 +++++++++- backend/thirdparty/stripe/models.py | 2 -- backend/thirdparty/stripe/views.py | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/account/tasks.py b/backend/account/tasks.py index 75ff897..565d65a 100644 --- a/backend/account/tasks.py +++ b/backend/account/tasks.py @@ -10,6 +10,7 @@ from .models import CustomUser logger = get_task_logger(__name__) +# TODO: předělat funkci ať funguje s base.html šablonou na emaily !!! def send_email_with_context(recipients, subject, message=None, template_name=None, html_template_name=None, context=None): """ General function to send emails with a specific context. diff --git a/backend/commerce/models.py b/backend/commerce/models.py index 58812bf..6d91de7 100644 --- a/backend/commerce/models.py +++ b/backend/commerce/models.py @@ -546,7 +546,15 @@ class Refund(models.Model): "return_reason": return_reason, } - #TODO: přesunou zásilkovna field tady taky (ostranit z order několik balíku) + #TODO: přesunou zásilkovna field tady taky (zkontrolovat jestli jsou views napojené a použít metodu send z carrier) + carrier = models.OneToOneField( + "Carrier", + on_delete=models.CASCADE, + related_name="refund", + null=True, + blank=True + ) + html_string = render_to_string("refund/customer_in_package_returning_form.html", context) pdf_bytes = HTML(string=html_string).write_pdf() diff --git a/backend/thirdparty/stripe/models.py b/backend/thirdparty/stripe/models.py index f80f3a3..414316b 100644 --- a/backend/thirdparty/stripe/models.py +++ b/backend/thirdparty/stripe/models.py @@ -3,8 +3,6 @@ from django.apps import apps # Create your models here. -#TODO: logika a interakce bude na stripu (třeba aktualizovaní objednávky na zaplacenou apod.) - from .client import StripeClient class StripeModel(models.Model): diff --git a/backend/thirdparty/stripe/views.py b/backend/thirdparty/stripe/views.py index f940959..bc7c362 100644 --- a/backend/thirdparty/stripe/views.py +++ b/backend/thirdparty/stripe/views.py @@ -26,12 +26,13 @@ class StripeWebhook(APIView): sig_header = request.META['HTTP_STRIPE_SIGNATURE'] try: - #build stripe event + #build stripe event (api call) event = stripe.Webhook.construct_event( payload, sig_header, os.getenv("STRIPE_WEBHOOK_SECRET") ) except ValueError as e: + # TODO: doupravit error handling, dodělat v modelu možnost pro uložení chyby a status ERROR logger.error(f"Invalid payload: {e}") return HttpResponse(status=400)