mirror of
https://github.com/pretix/pretix.git
synced 2026-05-03 14:54:04 +00:00
Order cancellation: Allow to set step size for fee amount
This commit is contained in:
@@ -668,6 +668,7 @@ class EventSettingsSerializer(SettingsSerializer):
|
||||
'cancel_allow_user_paid_keep_percentage',
|
||||
'cancel_allow_user_paid_adjust_fees',
|
||||
'cancel_allow_user_paid_adjust_fees_explanation',
|
||||
'cancel_allow_user_paid_adjust_fees_step',
|
||||
'cancel_allow_user_paid_refund_as_giftcard',
|
||||
'cancel_allow_user_paid_require_approval',
|
||||
'change_allow_user_variation',
|
||||
|
||||
@@ -1225,6 +1225,21 @@ DEFAULTS = {
|
||||
"e.g. to explain choosing a lower refund will help your organization.")
|
||||
)
|
||||
},
|
||||
'cancel_allow_user_paid_adjust_fees_step': {
|
||||
'default': None,
|
||||
'type': Decimal,
|
||||
'form_class': forms.DecimalField,
|
||||
'serializer_class': serializers.DecimalField,
|
||||
'serializer_kwargs': dict(
|
||||
max_digits=10, decimal_places=2
|
||||
),
|
||||
'form_kwargs': dict(
|
||||
max_digits=10, decimal_places=2,
|
||||
label=_("Step size for reduction amount"),
|
||||
help_text=_('By default, customers can choose an arbitrary amount for you to keep. If you set this to e.g. '
|
||||
'10, they will only be able to choose values in increments of 10.')
|
||||
)
|
||||
},
|
||||
'cancel_allow_user_paid_require_approval': {
|
||||
'default': 'False',
|
||||
'type': bool,
|
||||
|
||||
@@ -572,6 +572,7 @@ class CancelSettingsForm(SettingsForm):
|
||||
'cancel_allow_user_paid_keep_percentage',
|
||||
'cancel_allow_user_paid_adjust_fees',
|
||||
'cancel_allow_user_paid_adjust_fees_explanation',
|
||||
'cancel_allow_user_paid_adjust_fees_step',
|
||||
'cancel_allow_user_paid_refund_as_giftcard',
|
||||
'cancel_allow_user_paid_require_approval',
|
||||
'change_allow_user_variation',
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
{% bootstrap_field form.cancel_allow_user_paid_adjust_fees layout="control" %}
|
||||
<div data-display-dependency="#id_cancel_allow_user_paid_adjust_fees">
|
||||
{% bootstrap_field form.cancel_allow_user_paid_adjust_fees_explanation layout="control" %}
|
||||
{% bootstrap_field form.cancel_allow_user_paid_adjust_fees_step layout="control" %}
|
||||
</div>
|
||||
{% bootstrap_field form.cancel_allow_user_paid_refund_as_giftcard layout="control" %}
|
||||
{% if not gets_notification %}
|
||||
|
||||
@@ -62,13 +62,20 @@
|
||||
value="{{ cancel_fee|stringformat:".2f" }}"
|
||||
data-slider-min="{{ cancel_fee|stringformat:".2f" }}"
|
||||
data-slider-value="{{ cancel_fee|stringformat:".2f" }}"
|
||||
data-slider-step="0.01"
|
||||
data-slider-max="{{ order.payment_refund_sum|stringformat:".2f" }}"
|
||||
{% if request.event.settings.cancel_allow_user_paid_adjust_fees_step %}
|
||||
data-slider-ticks="{{ ticks }}"
|
||||
data-slider-lock-to-ticks="true"
|
||||
{% else %}
|
||||
data-slider-step="0.01"
|
||||
{% endif %}
|
||||
data-slider-max="{{ payment_refund_sum|stringformat:".2f" }}"
|
||||
data-slider-tooltip="hide"/>
|
||||
<div id="cancel-fee-refund"></div>
|
||||
</div>
|
||||
<div class="text-center" id="cancel-fee-custom-link">
|
||||
<a id="cancel-fee-custom"><small>{% trans "Enter custom amount" %}</small></a>
|
||||
{% if not request.event.settings.cancel_allow_user_paid_adjust_fees_step %}
|
||||
<a id="cancel-fee-custom"><small>{% trans "Enter custom amount" %}</small></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import inspect
|
||||
import json
|
||||
import mimetypes
|
||||
import os
|
||||
import re
|
||||
@@ -786,16 +787,27 @@ class OrderCancel(EventViewMixin, OrderDetailMixin, TemplateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
ctx['order'] = self.order
|
||||
prs = self.order.payment_refund_sum
|
||||
fee = self.order.user_cancel_fee
|
||||
refund_amount = self.order.payment_refund_sum - fee
|
||||
refund_amount = prs - fee
|
||||
proposals = self.order.propose_auto_refunds(refund_amount)
|
||||
ctx['cancel_fee'] = fee
|
||||
ctx['refund_amount'] = refund_amount
|
||||
ctx['payment_refund_sum'] = prs
|
||||
ctx['can_auto_refund'] = sum(proposals.values()) == refund_amount
|
||||
ctx['proposals'] = [
|
||||
p.payment_provider.payment_presale_render(payment=p)
|
||||
for p in proposals
|
||||
]
|
||||
if self.request.event.settings.cancel_allow_user_paid_adjust_fees_step:
|
||||
steps = [fee]
|
||||
s = fee
|
||||
while s < prs:
|
||||
steps.append(s)
|
||||
s += self.request.event.settings.cancel_allow_user_paid_adjust_fees_step
|
||||
if prs not in steps:
|
||||
steps.append(prs)
|
||||
ctx['ticks'] = json.dumps([float(p) for p in steps])
|
||||
return ctx
|
||||
|
||||
|
||||
@@ -831,6 +843,11 @@ class OrderCancelDo(EventViewMixin, OrderDetailMixin, AsyncAction, View):
|
||||
messages.error(request, _('You chose an invalid cancellation fee.'))
|
||||
return redirect(self.get_order_url())
|
||||
if custom_fee is not None and fee <= custom_fee <= self.order.payment_refund_sum:
|
||||
if self.request.event.settings.cancel_allow_user_paid_adjust_fees_step:
|
||||
if (custom_fee - fee) % self.request.event.settings.cancel_allow_user_paid_adjust_fees_step != Decimal('0.00'):
|
||||
messages.error(request, _('You chose an invalid cancellation fee.'))
|
||||
return redirect(self.get_order_url())
|
||||
|
||||
fee = custom_fee
|
||||
else:
|
||||
messages.error(request, _('You chose an invalid cancellation fee.'))
|
||||
|
||||
@@ -214,6 +214,11 @@ h2.subevent-head {
|
||||
@include slider_background-image($brand-success, darken($brand-success, 5%), mix($brand-success, darken($brand-success, 5%)));
|
||||
}
|
||||
|
||||
.slider-tick-container {
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
input {
|
||||
flex: 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user