forked from CGM_Public/pretix_original
Fix partial PATCH for gift cards (PRETIXEU-75P)
This commit is contained in:
@@ -114,20 +114,21 @@ class GiftCardSerializer(I18nAwareModelSerializer):
|
|||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
data = super().validate(data)
|
data = super().validate(data)
|
||||||
s = data['secret']
|
if 'secret' in data:
|
||||||
qs = GiftCard.objects.filter(
|
s = data['secret']
|
||||||
secret=s
|
qs = GiftCard.objects.filter(
|
||||||
).filter(
|
secret=s
|
||||||
Q(issuer=self.context["organizer"]) | Q(
|
).filter(
|
||||||
issuer__gift_card_collector_acceptance__collector=self.context["organizer"])
|
Q(issuer=self.context["organizer"]) | Q(
|
||||||
)
|
issuer__gift_card_collector_acceptance__collector=self.context["organizer"])
|
||||||
if self.instance:
|
|
||||||
qs = qs.exclude(pk=self.instance.pk)
|
|
||||||
if qs.exists():
|
|
||||||
raise ValidationError(
|
|
||||||
{'secret': _(
|
|
||||||
'A gift card with the same secret already exists in your or an affiliated organizer account.')}
|
|
||||||
)
|
)
|
||||||
|
if self.instance:
|
||||||
|
qs = qs.exclude(pk=self.instance.pk)
|
||||||
|
if qs.exists():
|
||||||
|
raise ValidationError(
|
||||||
|
{'secret': _(
|
||||||
|
'A gift card with the same secret already exists in your or an affiliated organizer account.')}
|
||||||
|
)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -147,6 +147,17 @@ def test_giftcard_patch(token_client, organizer, event, giftcard):
|
|||||||
assert giftcard.currency == "EUR"
|
assert giftcard.currency == "EUR"
|
||||||
assert not giftcard.testmode
|
assert not giftcard.testmode
|
||||||
|
|
||||||
|
resp = token_client.patch(
|
||||||
|
'/api/v1/organizers/{}/giftcards/{}/'.format(organizer.slug, giftcard.pk),
|
||||||
|
{
|
||||||
|
'value': '9.00',
|
||||||
|
},
|
||||||
|
format='json'
|
||||||
|
)
|
||||||
|
assert resp.status_code == 200
|
||||||
|
giftcard.refresh_from_db()
|
||||||
|
assert giftcard.value == Decimal('9.00')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_giftcard_patch_min_value(token_client, organizer, event, giftcard):
|
def test_giftcard_patch_min_value(token_client, organizer, event, giftcard):
|
||||||
|
|||||||
Reference in New Issue
Block a user