Order change: Allow to ignore quotas

This commit is contained in:
Raphael Michel
2019-02-11 16:15:54 +01:00
parent d073007fd7
commit f23de7e2c0
5 changed files with 19 additions and 3 deletions

View File

@@ -1306,7 +1306,7 @@ class OrderChangeManager:
except SendMailException:
logger.exception('Order changed email could not be sent')
def commit(self):
def commit(self, check_quotas=True):
if self._committed:
# an order change can only be committed once
raise OrderError(error_messages['internal'])
@@ -1323,7 +1323,8 @@ class OrderChangeManager:
with self.order.event.lock():
if self.order.status not in (Order.STATUS_PENDING, Order.STATUS_PAID):
raise OrderError(self.error_messages['not_pending_or_paid'])
self._check_quotas()
if check_quotas:
self._check_quotas()
self._check_complete_cancel()
self._perform_operations()
self._recalculate_total_and_payment_fee()

View File

@@ -177,6 +177,10 @@ class OtherOperationsForm(forms.Form):
'Send an email to the customer notifying that their order has been changed.'
)
)
ignore_quotas = forms.BooleanField(
label=_('Allow to overbook quotas when performing this operation'),
required=False,
)
def __init__(self, *args, **kwargs):
kwargs.pop('order')

View File

@@ -206,6 +206,9 @@
</div>
</div>
</div>
<div class="">
{% bootstrap_field other_form.ignore_quotas layout="" %}
</div>
<div class="form-group submit-group">
<a class="btn btn-default btn-lg"
href="{% url "control:event.order" event=request.event.slug organizer=request.event.organizer.slug code=order.code %}">

View File

@@ -1259,7 +1259,7 @@ class OrderChange(OrderView):
messages.error(self.request, _('An error occurred. Please see the details below.'))
else:
try:
ocm.commit()
ocm.commit(check_quotas=not self.other_form.cleaned_data['ignore_quotas'])
except OrderError as e:
messages.error(self.request, str(e))
else:

View File

@@ -816,6 +816,14 @@ class OrderChangeManagerTests(TestCase):
self.op1.refresh_from_db()
assert self.op1.item == self.ticket
def test_quota_ignore(self):
q = self.event.quotas.create(name='Test', size=0)
q.items.add(self.shirt)
self.ocm.change_item(self.op1, self.shirt, None)
self.ocm.commit(check_quotas=False)
self.op1.refresh_from_db()
assert self.op1.item == self.shirt
def test_quota_full_but_in_same(self):
q = self.event.quotas.create(name='Test', size=0)
q.items.add(self.shirt)