forked from CGM_Public/pretix_original
API: Fix using invoice address attributes in "include"
This commit is contained in:
@@ -636,7 +636,7 @@ class OrderSerializer(I18nAwareModelSerializer):
|
||||
for fname, field in list(self.fields.items()):
|
||||
if fname in includes:
|
||||
continue
|
||||
elif hasattr(field, 'child'):
|
||||
elif hasattr(field, 'child'): # Nested list serializers
|
||||
found_any = False
|
||||
for childfname, childfield in list(field.child.fields.items()):
|
||||
if f'{fname}.{childfname}' not in includes:
|
||||
@@ -645,6 +645,15 @@ class OrderSerializer(I18nAwareModelSerializer):
|
||||
found_any = True
|
||||
if not found_any:
|
||||
self.fields.pop(fname)
|
||||
elif isinstance(field, serializers.Serializer): # Nested serializers
|
||||
found_any = False
|
||||
for childfname, childfield in list(field.fields.items()):
|
||||
if f'{fname}.{childfname}' not in includes:
|
||||
field.fields.pop(childfname)
|
||||
else:
|
||||
found_any = True
|
||||
if not found_any:
|
||||
self.fields.pop(fname)
|
||||
else:
|
||||
self.fields.pop(fname)
|
||||
|
||||
|
||||
@@ -479,15 +479,19 @@ def test_include_exclude_fields(token_client, organizer, event, order, item, tax
|
||||
assert 'url' not in resp.data
|
||||
assert 'positions' not in resp.data
|
||||
|
||||
resp = token_client.get('/api/v1/organizers/{}/events/{}/orders/{}/?include=email&include=positions&exclude=positions.secret'.format(
|
||||
organizer.slug, event.slug, order.code
|
||||
))
|
||||
resp = token_client.get(
|
||||
'/api/v1/organizers/{}/events/{}/orders/{}/?include=email&include=positions&include=invoice_address.name&exclude=positions.secret'.format(
|
||||
organizer.slug, event.slug, order.code
|
||||
)
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert 'email' in resp.data
|
||||
assert 'url' not in resp.data
|
||||
assert 'positions' in resp.data
|
||||
assert 'subevent' in resp.data['positions'][0]
|
||||
assert 'secret' not in resp.data['positions'][0]
|
||||
assert 'city' not in resp.data['invoice_address']
|
||||
assert 'name' in resp.data['invoice_address']
|
||||
|
||||
resp = token_client.get('/api/v1/organizers/{}/events/{}/orders/{}/?include=email&include=positions.subevent'.format(
|
||||
organizer.slug, event.slug, order.code
|
||||
|
||||
Reference in New Issue
Block a user