Voucher import: Fix quota name check

This commit is contained in:
Raphael Michel
2024-04-24 10:28:10 +02:00
parent 239a7746df
commit 11a6390cfc
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -251,7 +251,7 @@ class QuotaColumn(ImportColumn):
raise ValidationError(_("You cannot specify a quota if you specified a product."))
matches = [
q for q in self.quotas
if str(q.pk) == value or any((v and v == value) for v in i18n_flat(q.name))
if str(q.pk) == value or q.name == value
]
if len(matches) == 0:
raise ValidationError(_("No matching variation was found."))
@@ -180,3 +180,18 @@ def test_price_mode_validation(event, item, user):
v = event.vouchers.get(code="ABCDE123")
assert v.price_mode == "percent"
assert v.value == Decimal("1.00")
@pytest.mark.django_db
@scopes_disabled()
def test_quota(event, item, user):
settings = dict(DEFAULT_SETTINGS)
settings['quota'] = 'csv:B'
settings['item'] = 'empty'
q = event.quotas.create(name="Ticket", size=100)
import_vouchers.apply(
args=(event.pk, inputfile_factory().id, settings, 'en', user.pk)
).get()
assert event.vouchers.count() == 2
v = event.vouchers.get(code="ABCDE123")
assert v.quota == q