API: Fix creating free orders requiring approval

This commit is contained in:
Raphael Michel
2024-03-19 10:10:57 +01:00
parent 9513b6e8d7
commit 4694719a53
2 changed files with 7 additions and 2 deletions
+3 -1
View File
@@ -1585,7 +1585,7 @@ class OrderCreateSerializer(I18nAwareModelSerializer):
if order.total == Decimal('0.00') and validated_data.get('status') == Order.STATUS_PAID and not payment_provider:
payment_provider = 'free'
if order.total == Decimal('0.00') and validated_data.get('status') != Order.STATUS_PAID:
if order.total == Decimal('0.00') and validated_data.get('status') != Order.STATUS_PAID and not validated_data.get('require_approval'):
order.status = Order.STATUS_PAID
order.save()
order.payments.create(
@@ -1597,6 +1597,8 @@ class OrderCreateSerializer(I18nAwareModelSerializer):
elif validated_data.get('status') == Order.STATUS_PAID:
if not payment_provider:
raise ValidationError('You cannot create a paid order without a payment provider.')
if validated_data.get('require_approval'):
raise ValidationError('You cannot create a paid order that requires approval.')
order.payments.create(
amount=order.total,
provider=payment_provider,
+4 -1
View File
@@ -547,12 +547,14 @@ def test_order_create_autocheckin(token_client, organizer, event, item, quota, q
@pytest.mark.django_db
def test_order_create_require_approval(token_client, organizer, event, item, quota, question):
def test_order_create_require_approval_free(token_client, organizer, event, item, quota, question):
res = copy.deepcopy(ORDER_CREATE_PAYLOAD)
res['require_approval'] = True
res['send_email'] = True
res['positions'][0]['item'] = item.pk
res['positions'][0]['answers'][0]['question'] = question.pk
res['positions'][0]['price'] = '0.00'
res['fees'] = []
djmail.outbox = []
resp = token_client.post(
'/api/v1/organizers/{}/events/{}/orders/'.format(
@@ -563,6 +565,7 @@ def test_order_create_require_approval(token_client, organizer, event, item, quo
with scopes_disabled():
o = Order.objects.get(code=resp.data['code'])
assert o.require_approval
assert o.status == Order.STATUS_PENDING
assert len(djmail.outbox) == 1
assert djmail.outbox[0].subject == "Your order: {}".format(resp.data['code'])
assert "approval" in djmail.outbox[0].body