From 04ef097eb13b8ae9116c486fbb582ae4aa2c37c0 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 28 Feb 2024 16:10:53 +0100 Subject: [PATCH] Fix #65 -- Disallow None value for product default prices (#3847) * Fix #65 -- Disallow None value for product default prices * Fix #65 -- Disallow None value for product default prices * Rebase migration --- .../0257_item_default_price_not_null.py | 19 +++++++++++++++++++ src/pretix/base/models/items.py | 2 +- src/tests/api/test_cart.py | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/pretix/base/migrations/0257_item_default_price_not_null.py diff --git a/src/pretix/base/migrations/0257_item_default_price_not_null.py b/src/pretix/base/migrations/0257_item_default_price_not_null.py new file mode 100644 index 0000000000..16b0511a4e --- /dev/null +++ b/src/pretix/base/migrations/0257_item_default_price_not_null.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.9 on 2024-01-30 11:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("pretixbase", "0256_itemvariation_unavail_modes"), + ] + + operations = [ + migrations.AlterField( + model_name="item", + name="default_price", + field=models.DecimalField(decimal_places=2, default=0, max_digits=13), + preserve_default=False, + ), + ] diff --git a/src/pretix/base/models/items.py b/src/pretix/base/models/items.py index f518a3ec2a..8e8bf7070e 100644 --- a/src/pretix/base/models/items.py +++ b/src/pretix/base/models/items.py @@ -430,7 +430,7 @@ class Item(LoggedModel): help_text=_("If this product has multiple variations, you can set different prices for each of the " "variations. If a variation does not have a special price or if you do not have variations, " "this price will be used."), - max_digits=13, decimal_places=2, null=True + max_digits=13, decimal_places=2, ) free_price = models.BooleanField( default=False, diff --git a/src/tests/api/test_cart.py b/src/tests/api/test_cart.py index 4767411c20..348e189a8d 100644 --- a/src/tests/api/test_cart.py +++ b/src/tests/api/test_cart.py @@ -934,7 +934,7 @@ def test_cartpos_create_with_voucher_unknown(token_client, organizer, event, ite @pytest.mark.django_db def test_cartpos_create_with_voucher_invalid_item(token_client, organizer, event, item, quota): with scopes_disabled(): - item2 = event.items.create(name="item2") + item2 = event.items.create(name="item2", default_price=0) voucher = event.vouchers.create(code="FOOBAR", item=item2) res = copy.deepcopy(CARTPOS_CREATE_PAYLOAD) res['item'] = item.pk