Allow to add a comment when cancelling an order (#2580)

This commit is contained in:
Raphael Michel
2022-04-12 09:53:02 +02:00
committed by GitHub
parent f7c0921f18
commit 3cdf578c14
43 changed files with 130 additions and 10 deletions

View File

@@ -345,6 +345,7 @@ class OrderViewSet(viewsets.ModelViewSet):
@action(detail=True, methods=['POST'])
def mark_canceled(self, request, **kwargs):
send_mail = request.data.get('send_email', True)
comment = request.data.get('comment', None)
cancellation_fee = request.data.get('cancellation_fee', None)
if cancellation_fee:
try:
@@ -367,6 +368,7 @@ class OrderViewSet(viewsets.ModelViewSet):
device=request.auth if isinstance(request.auth, Device) else None,
oauth_application=request.auth.application if isinstance(request.auth, OAuthAccessToken) else None,
send_mail=send_mail,
email_comment=comment,
cancellation_fee=cancellation_fee
)
except OrderError as e:

View File

@@ -384,7 +384,7 @@ def deny_order(order, comment='', user=None, send_mail: bool=True, auth=None):
def _cancel_order(order, user=None, send_mail: bool=True, api_token=None, device=None, oauth_application=None,
cancellation_fee=None, keep_fees=None, cancel_invoice=True):
cancellation_fee=None, keep_fees=None, cancel_invoice=True, comment=None):
"""
Mark this order as canceled
:param order: The order to change
@@ -481,7 +481,7 @@ def _cancel_order(order, user=None, send_mail: bool=True, api_token=None, device
Voucher.objects.filter(pk=position.voucher.pk).update(redeemed=Greatest(0, F('redeemed') - 1))
order.log_action('pretix.event.order.canceled', user=user, auth=api_token or oauth_application or device,
data={'cancellation_fee': cancellation_fee})
data={'cancellation_fee': cancellation_fee, 'comment': comment})
order.cancellation_requests.all().delete()
order.create_transactions()
@@ -489,7 +489,7 @@ def _cancel_order(order, user=None, send_mail: bool=True, api_token=None, device
if send_mail:
email_template = order.event.settings.mail_text_order_canceled
with language(order.locale, order.event.settings.region):
email_context = get_email_context(event=order.event, order=order)
email_context = get_email_context(event=order.event, order=order, comment=comment or "")
email_subject = _('Order canceled: %(code)s') % {'code': order.code}
try:
order.send_mail(
@@ -2506,15 +2506,15 @@ def _try_auto_refund(order, auto_refund=True, manual_refund=False, allow_partial
@app.task(base=ProfiledTask, bind=True, max_retries=5, default_retry_delay=1, throws=(OrderError,))
@scopes_disabled()
def cancel_order(self, order: int, user: int=None, send_mail: bool=True, api_token=None, oauth_application=None,
device=None, cancellation_fee=None, try_auto_refund=False, refund_as_giftcard=False, comment=None,
cancel_invoice=True):
device=None, cancellation_fee=None, try_auto_refund=False, refund_as_giftcard=False,
email_comment=None, refund_comment=None, cancel_invoice=True):
try:
try:
ret = _cancel_order(order, user, send_mail, api_token, device, oauth_application,
cancellation_fee, cancel_invoice=cancel_invoice)
cancellation_fee, cancel_invoice=cancel_invoice, comment=email_comment)
if try_auto_refund:
_try_auto_refund(order, refund_as_giftcard=refund_as_giftcard,
comment=comment)
comment=refund_comment)
return ret
except LockTimeoutException:
self.retry()

View File

@@ -1914,6 +1914,8 @@ Your {event} team"""))
your order {code} for {event} has been canceled.
{comment}
You can view the details of your order at
{url}

View File

@@ -1075,7 +1075,7 @@ class MailSettingsForm(SettingsForm):
'mail_text_order_free': ['event', 'order'],
'mail_text_order_free_attendee': ['event', 'order', 'position'],
'mail_text_order_changed': ['event', 'order'],
'mail_text_order_canceled': ['event', 'order'],
'mail_text_order_canceled': ['event', 'order', 'comment'],
'mail_text_order_expire_warning': ['event', 'order'],
'mail_text_order_custom_mail': ['event', 'order'],
'mail_text_download_reminder': ['event', 'order'],

View File

@@ -167,6 +167,12 @@ class CancelForm(ForceQuotaConfirmationForm):
initial=True,
required=False
)
comment = forms.CharField(
label=_('Comment (will be sent to the user)'),
help_text=_('Will be included in the notification email when the respective placeholder is present in the '
'configured email text.'),
required=False,
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

View File

@@ -341,7 +341,6 @@ def pretixcontrol_logentry_display(sender: Event, logentry: LogEntry, **kwargs):
'pretix.event.order.paid': _('The order has been marked as paid.'),
'pretix.event.order.cancellationrequest.deleted': _('The cancellation request has been deleted.'),
'pretix.event.order.refunded': _('The order has been refunded.'),
'pretix.event.order.canceled': _('The order has been canceled.'),
'pretix.event.order.reactivated': _('The order has been reactivated.'),
'pretix.event.order.deleted': _('The test mode order {code} has been deleted.'),
'pretix.event.order.placed': _('The order has been created.'),
@@ -532,6 +531,13 @@ def pretixcontrol_logentry_display(sender: Event, logentry: LogEntry, **kwargs):
bleach.clean(logentry.parsed_data.get('msg'), tags=[], strip=True)
)
if logentry.action_type == 'pretix.event.order.canceled':
comment = logentry.parsed_data.get('comment')
if comment:
return _('The order has been canceled (comment: "{}").').format(comment)
else:
return _('The order has been canceled.')
if logentry.action_type in ('pretix.control.views.checkin.reverted', 'pretix.event.checkin.reverted'):
if 'list' in data:
try:

View File

@@ -35,6 +35,7 @@
{% bootstrap_field form.cancellation_fee layout='' %}
{% endif %}
{% bootstrap_field form.send_email layout='' %}
{% bootstrap_field form.comment layout='' %}
{% if form.cancel_invoice %}
{% bootstrap_field form.cancel_invoice layout='' %}
{% endif %}

View File

@@ -1266,6 +1266,7 @@ class OrderTransition(OrderView):
elif self.order.cancel_allowed() and to == 'c' and self.mark_canceled_form.is_valid():
try:
cancel_order(self.order.pk, user=self.request.user,
email_comment=self.mark_canceled_form.cleaned_data['comment'],
send_mail=self.mark_canceled_form.cleaned_data['send_email'],
cancel_invoice=self.mark_canceled_form.cleaned_data.get('cancel_invoice', True),
cancellation_fee=self.mark_canceled_form.cleaned_data.get('cancellation_fee'))

View File

@@ -8106,6 +8106,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8116,6 +8118,8 @@ msgstr ""
"\n"
"تم إلغاء طلبك {code} الخاص ب {event}.\n"
"\n"
"{comment}\n"
"\n"
"يمكنك عرض تفاصيل طلبك من خلال:\n"
"{url}\n"
"\n"

View File

@@ -8340,6 +8340,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8350,6 +8352,8 @@ msgstr ""
"\n"
"s'ha cancel·lat la vostra comanda {code} per {event}.\n"
"\n"
"{comment}\n"
"\n"
"Podeu veure els detalls de la vostra comanda a\n"
"{url}\n"
"\n"

View File

@@ -7501,6 +7501,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -7976,6 +7976,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -7986,6 +7988,8 @@ msgstr ""
"\n"
"Din bestilling {code} til {event} er blevet annulleret.\n"
"\n"
"{comment}\n"
"\n"
"Du kan se detaljerne for din bestilling på\n"
"{url}\n"
"\n"

View File

@@ -8303,6 +8303,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8313,6 +8315,8 @@ msgstr ""
"\n"
"Ihre Bestellung {code} für {event} wurde storniert.\n"
"\n"
"{comment}\n"
"\n"
"Sie können Ihre Bestellung unter folgender Adresse einsehen:\n"
"{url}\n"
"\n"

View File

@@ -8291,6 +8291,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8301,6 +8303,8 @@ msgstr ""
"\n"
"deine Bestellung {code} für {event} wurde storniert.\n"
"\n"
"{comment}\n"
"\n"
"Du kannst deine Bestellung unter folgender Adresse einsehen:\n"
"{url}\n"
"\n"

View File

@@ -8697,6 +8697,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8707,6 +8709,8 @@ msgstr ""
"\n"
"η παραγγελία σας {code} για {event} έχει ακυρωθεί.\n"
"\n"
"{comment}\n"
"\n"
"Μπορείτε να δείτε τις λεπτομέρειες της παραγγελίας σας στο\n"
"{url}\n"
"\n"

View File

@@ -8554,6 +8554,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8564,6 +8566,8 @@ msgstr ""
"\n"
"su pedido {code} para {event} ha sido cancelado. \n"
"\n"
"{comment}\n"
"\n"
"Puede ver los detalles de su pedido en\n"
"{url}. \n"
"\n"

View File

@@ -7392,6 +7392,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -8798,6 +8798,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8808,6 +8810,8 @@ msgstr ""
"\n"
"votre commande {code} pour {event} a été annulée.\n"
"\n"
"{comment}\n"
"\n"
"Vous pouvez consulter les détails de votre commande à l'adresse suivante\n"
"{url}\n"
"\n"

View File

@@ -8753,6 +8753,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8763,6 +8765,8 @@ msgstr ""
"\n"
"su pedido {code} para {event} ha sido cancelado. \n"
"\n"
"{comment}\n"
"\n"
"Puede ver los detalles de su pedido en\n"
"{url}. \n"
"\n"

View File

@@ -7341,6 +7341,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -7435,6 +7435,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -7673,6 +7673,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -7683,6 +7685,8 @@ msgstr ""
"\n"
"il tuo ordine {code} per {event} è stato cancellato.\n"
"\n"
"{comment}\n"
"\n"
"Puoi vedere i dettagli del tuo ordine qui:\n"
"{url}\n"
"\n"

View File

@@ -7361,6 +7361,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -7698,6 +7698,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -7390,6 +7390,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -8302,6 +8302,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8312,6 +8314,8 @@ msgstr ""
"\n"
"Uw bestelling {code} voor {event} is geannuleerd.\n"
"\n"
"{comment}\n"
"\n"
"U kunt de gegevens van uw bestelling bekijken op\n"
"{url}\n"
"\n"

View File

@@ -7339,6 +7339,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -8323,6 +8323,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8333,6 +8335,8 @@ msgstr ""
"\n"
"Je bestelling {code} voor {event} is geannuleerd.\n"
"\n"
"{comment}\n"
"\n"
"Je kan de gegevens van je bestelling bekijken op {url}\n"
"\n"
"Met vriendelijke groeten,\n"

View File

@@ -7902,6 +7902,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -7340,6 +7340,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -7380,6 +7380,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -8011,6 +8011,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -8383,6 +8383,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8393,6 +8395,8 @@ msgstr ""
"\n"
"a sua encomenda {code} para {event} foi cancelada.\n"
"\n"
"{comment}\n"
"\n"
"Pode ver os detalhes da sua encomenda em\n"
"{url}\n"
"\n"

View File

@@ -7342,6 +7342,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -8076,6 +8076,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -7346,6 +7346,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -7997,6 +7997,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -7949,6 +7949,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -7959,6 +7961,8 @@ msgstr ""
"\n"
"din beställning {code} för {event} har annullerats.\n"
"\n"
"{comment}\n"
"\n"
"Du kan se detaljerna för din beställning på\n"
"{url}\n"
"\n"

View File

@@ -8773,6 +8773,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8783,6 +8785,8 @@ msgstr ""
"\n"
"{event} için {code} sipraşiniz iptal edilmiştir.\n"
"\n"
"{comment}\n"
"\n"
"Sipraşinizinin detaylarını bu adresten inceleyebilirsiniz\n"
"{url}\n"
"\n"

View File

@@ -7340,6 +7340,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"

View File

@@ -8150,6 +8150,8 @@ msgid ""
"\n"
"your order {code} for {event} has been canceled.\n"
"\n"
"{comment}\n"
"\n"
"You can view the details of your order at\n"
"{url}\n"
"\n"
@@ -8160,6 +8162,8 @@ msgstr ""
"\n"
"您{event}的订单{code}已被取消。\n"
"\n"
"{comment}\n"
"\n"
"您可以在{url}查看订单的详细信息\n"
"\n"
"致敬,\n"

View File

@@ -953,7 +953,7 @@ class OrderCancelDo(EventViewMixin, OrderDetailMixin, AsyncAction, View):
else:
comment = gettext('Canceled by customer')
return self.do(self.order.pk, cancellation_fee=fee, try_auto_refund=auto_refund, refund_as_giftcard=giftcard,
comment=comment)
refund_comment=comment)
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)