diff --git a/backend/account/templates/emails/email_verification.html b/backend/account/templates/email/email_verification.html similarity index 100% rename from backend/account/templates/emails/email_verification.html rename to backend/account/templates/email/email_verification.html diff --git a/backend/account/templates/emails/email_verification.txt b/backend/account/templates/email/email_verification.txt similarity index 100% rename from backend/account/templates/emails/email_verification.txt rename to backend/account/templates/email/email_verification.txt diff --git a/backend/account/templates/emails/password_reset.html b/backend/account/templates/email/password_reset.html similarity index 100% rename from backend/account/templates/emails/password_reset.html rename to backend/account/templates/email/password_reset.html diff --git a/backend/account/templates/emails/password_reset.txt b/backend/account/templates/email/password_reset.txt similarity index 100% rename from backend/account/templates/emails/password_reset.txt rename to backend/account/templates/email/password_reset.txt diff --git a/backend/account/templates/emails/test.html b/backend/account/templates/email/test.html similarity index 100% rename from backend/account/templates/emails/test.html rename to backend/account/templates/email/test.html diff --git a/backend/account/templates/emails/test.txt b/backend/account/templates/email/test.txt similarity index 100% rename from backend/account/templates/emails/test.txt rename to backend/account/templates/email/test.txt diff --git a/backend/commerce/models.py b/backend/commerce/models.py index bd0e825..58812bf 100644 --- a/backend/commerce/models.py +++ b/backend/commerce/models.py @@ -10,6 +10,7 @@ from django.core.validators import MaxValueValidator, MinValueValidator from weasyprint import HTML import os +from backend.commerce.tasks import notify_order_sended from configuration.models import ShopConfiguration from thirdparty.zasilkovna.models import ZasilkovnaPacket from thirdparty.stripe.models import StripeModel @@ -243,9 +244,16 @@ class Carrier(models.Model): self.returning = False self.save() + elif self.shipping_method == self.SHIPPING.STORE: + self.state = self.STATE.READY_TO_PICKUP + self.save() + else: raise ValidationError("Tato metoda dopravy nepodporuje objednání přepravy.") + + notify_order_sended.delay(order=self.orders.first(), user=self.orders.first().user) + #... další logika pro jiné způsoby dopravy #TODO: přidat notifikace uživateli, jak pro zásilkovnu, tak pro vyzvednutí v obchodě! diff --git a/backend/commerce/tasks.py b/backend/commerce/tasks.py index 60a9829..c9e76be 100644 --- a/backend/commerce/tasks.py +++ b/backend/commerce/tasks.py @@ -1,4 +1,8 @@ from .models import Order +from account.models import User +from account.tasks import send_email_with_context +from celery import shared_task + from django.utils import timezone def delete_expired_orders(): @@ -8,3 +12,132 @@ def delete_expired_orders(): return count +# -- NOTIFICATIONS CARRIER -- + +# Zásilkovna +@shared_task +def notify_zasilkovna_sended(order:Order = None, user:User = None, **kwargs): + if not order or not user: + raise ValueError("Order and User must be provided for notification.") + + if kwargs: + print("Additional kwargs received in notify_order_sended:", kwargs) + + send_email_with_context( + user.email, + subject="Your order has been shipped", + template_name="emails/order_sended.txt", + html_template_name="emails/order_sended.html", + context={ + "user": user, + "order": order, + }) + + pass + +# Shop +@shared_task +def notify_Ready_to_pickup(order:Order = None, user:User = None, **kwargs): + if not order or not user: + raise ValueError("Order and User must be provided for notification.") + + if kwargs: + print("Additional kwargs received in notify_order_sended:", kwargs) + + send_email_with_context( + user.email, + subject="Your order has been shipped", + template_name="emails/order_sended.txt", + html_template_name="emails/order_sended.html", + context={ + "user": user, + "order": order, + }) + + pass + + +# -- NOTIFICATIONS ORDER -- + +@shared_task +def notify_order_successfuly_created(order:Order = None, user:User = None, **kwargs): + if not order or not user: + raise ValueError("Order and User must be provided for notification.") + + if kwargs: + print("Additional kwargs received in notify_order_successfuly_created:", kwargs) + + send_email_with_context( + user.email, + subject="Your order has been successfully created", + template_name="emails/order_created.txt", + html_template_name="emails/order_created.html", + context={ + "user": user, + "order": order, + }) + + pass + + +@shared_task +def notify_about_missing_payment(order:Order = None, user:User = None, **kwargs): + if not order or not user: + raise ValueError("Order and User must be provided for notification.") + + if kwargs: + print("Additional kwargs received in notify_about_missing_payment:", kwargs) + + send_email_with_context( + user.email, + subject="Payment missing for your order", + template_name="emails/order_missing_payment.txt", + html_template_name="emails/order_missing_payment.html", + context={ + "user": user, + "order": order, + }) + + pass + + +def notify_refund_items_arrived(order:Order = None, user:User = None, **kwargs): + if not order or not user: + raise ValueError("Order and User must be provided for notification.") + + if kwargs: + print("Additional kwargs received in notify_refund_items_arrived:", kwargs) + + send_email_with_context( + user.email, + subject="Your refund items have arrived", + template_name="emails/order_refund_items_arrived.txt", + html_template_name="emails/order_refund_items_arrived.html", + context={ + "user": user, + "order": order, + }) + + pass + + +# Refund accepted, retuning money +@shared_task +def notify_refund_accepted(order:Order = None, user:User = None, **kwargs): + if not order or not user: + raise ValueError("Order and User must be provided for notification.") + + if kwargs: + print("Additional kwargs received in notify_refund_accepted:", kwargs) + + send_email_with_context( + user.email, + subject="Your refund has been accepted", + template_name="emails/order_refund_accepted.txt", + html_template_name="emails/order_refund_accepted.html", + context={ + "user": user, + "order": order, + }) + + pass \ No newline at end of file diff --git a/backend/commerce/templates/refund/customer_in_package_returning_form.html b/backend/commerce/templates/email/refund/customer_in_package_returning_form.html similarity index 100% rename from backend/commerce/templates/refund/customer_in_package_returning_form.html rename to backend/commerce/templates/email/refund/customer_in_package_returning_form.html diff --git a/backend/commerce/templates/email/shipping/ready_to_pickup/ready_to_pickup.html b/backend/commerce/templates/email/shipping/ready_to_pickup/ready_to_pickup.html new file mode 100644 index 0000000..e69de29 diff --git a/backend/commerce/templates/email/shipping/ready_to_pickup/ready_to_pickup.txt b/backend/commerce/templates/email/shipping/ready_to_pickup/ready_to_pickup.txt new file mode 100644 index 0000000..e69de29 diff --git a/backend/commerce/templates/email/shipping/zasilkovna/zasilkovna_sended.html b/backend/commerce/templates/email/shipping/zasilkovna/zasilkovna_sended.html new file mode 100644 index 0000000..e69de29 diff --git a/backend/commerce/templates/email/shipping/zasilkovna/zasilkovna_sended.txt b/backend/commerce/templates/email/shipping/zasilkovna/zasilkovna_sended.txt new file mode 100644 index 0000000..e69de29 diff --git a/backend/templates/email/base.html b/backend/templates/email/base.html new file mode 100644 index 0000000..62660b1 --- /dev/null +++ b/backend/templates/email/base.html @@ -0,0 +1,51 @@ + + + + + Email + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ {% include 'email/components/header.html' %} +
+ + {% if content_template %} + {% include content_template %} + {% else %} +

missing content_template !!!

+ {% endif %} + +
+ {% include 'email/components/footer.html' %} +
+ +
+ + + diff --git a/backend/templates/email/components/footer.html b/backend/templates/email/components/footer.html new file mode 100644 index 0000000..257ff1d --- /dev/null +++ b/backend/templates/email/components/footer.html @@ -0,0 +1,8 @@ + + + + +
+ Tento e-mail byl odeslán automaticky.
+ © {{ site_name|default:"E-shop" }} +
diff --git a/backend/templates/email/components/header.html b/backend/templates/email/components/header.html new file mode 100644 index 0000000..f7fc609 --- /dev/null +++ b/backend/templates/email/components/header.html @@ -0,0 +1,9 @@ + + + + +
+

+ {{ site_name|default:"E-shop" }} +

+