Skip to content

Commit

Permalink
Fix sending out cancellation emails
Browse files Browse the repository at this point in the history
  • Loading branch information
bruecksen committed Nov 18, 2024
1 parent 64f5e93 commit 5d9f671
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions bakeup/shop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ def send_order_confirm_email(self, request):
except Exception:
logger.exception("Sending order confirm email failed.", stack_info=True)

def send_order_cancellation_email(self, request):
def generate_order_cancellation_email(self, request):
from bakeup.pages.models import BrandSettings, EmailSettings

try:
Expand Down Expand Up @@ -1074,10 +1074,10 @@ def send_order_cancellation_email(self, request):
[user_email],
)
message.content_subtype = "html"
message.send(fail_silently=False)
return message
except Exception:
logger.exception(
"Sending order cancellation email failed.", stack_info=True
"Generating order cancellation email failed.", stack_info=True
)


Expand Down
14 changes: 12 additions & 2 deletions bakeup/shop/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,21 @@ def customer_order_add_or_update(request, production_day):
customer=request.user.customer,
)
logger.error("Order #%s: order will be completely deleted!", customer_order)
customer_order.delete()
email = None
if EmailSettings.load(
request_or_site=request
).send_email_order_cancellation:
customer_order.send_order_cancellation_email(request)
email = customer_order.generate_order_cancellation_email(request)
customer_order.delete()
if email:
try:
email.send(fail_silently=False)
except Exception as e:
logger.error(
"Order #%s: Error while sending cancellation email: %s",
customer_order,
e,
)
messages.add_message(
request,
messages.INFO,
Expand Down

0 comments on commit 5d9f671

Please sign in to comment.