Skip to content

Commit 5d9f671

Browse files
committed
Fix sending out cancellation emails
1 parent 64f5e93 commit 5d9f671

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

bakeup/shop/models.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ def send_order_confirm_email(self, request):
10381038
except Exception:
10391039
logger.exception("Sending order confirm email failed.", stack_info=True)
10401040

1041-
def send_order_cancellation_email(self, request):
1041+
def generate_order_cancellation_email(self, request):
10421042
from bakeup.pages.models import BrandSettings, EmailSettings
10431043

10441044
try:
@@ -1074,10 +1074,10 @@ def send_order_cancellation_email(self, request):
10741074
[user_email],
10751075
)
10761076
message.content_subtype = "html"
1077-
message.send(fail_silently=False)
1077+
return message
10781078
except Exception:
10791079
logger.exception(
1080-
"Sending order cancellation email failed.", stack_info=True
1080+
"Generating order cancellation email failed.", stack_info=True
10811081
)
10821082

10831083

bakeup/shop/views.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,21 @@ def customer_order_add_or_update(request, production_day):
176176
customer=request.user.customer,
177177
)
178178
logger.error("Order #%s: order will be completely deleted!", customer_order)
179-
customer_order.delete()
179+
email = None
180180
if EmailSettings.load(
181181
request_or_site=request
182182
).send_email_order_cancellation:
183-
customer_order.send_order_cancellation_email(request)
183+
email = customer_order.generate_order_cancellation_email(request)
184+
customer_order.delete()
185+
if email:
186+
try:
187+
email.send(fail_silently=False)
188+
except Exception as e:
189+
logger.error(
190+
"Order #%s: Error while sending cancellation email: %s",
191+
customer_order,
192+
e,
193+
)
184194
messages.add_message(
185195
request,
186196
messages.INFO,

0 commit comments

Comments
 (0)