Files
vontor-cz/backend/commerce/tasks.py
David Bruno Vontor 4cbebff43b Add production Docker setup and update backend/frontend configs
Introduces .dockerignore, production Dockerfile and nginx config for frontend, and refactors docker-compose.yml for multi-service deployment. Updates backend and frontend code to support public API tagging, improves refund handling, adds test email endpoint, and migrates Orval config to TypeScript. Removes unused frontend Dockerfile and updates dependencies for React Query and Orval.
2025-12-05 18:22:35 +01:00

146 lines
4.2 KiB
Python

from account.models import User
from account.tasks import send_email_with_context
from celery import shared_task
from django.apps import apps
from django.utils import timezone
Order = apps.get_model('commerce', 'Order')
def delete_expired_orders():
expired_orders = Order.objects.filter(status=Order.STATUS_CHOICES.CANCELLED, created_at__lt=timezone.now() - timezone.timedelta(hours=24))
count = expired_orders.count()
expired_orders.delete()
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