Replace Item.hidden_if_available with relationship to other Item (#3686)

* draft

* Implementation that is closer to old one

* Fix tests

* Add tests

* Update src/pretix/control/forms/item.py

Co-authored-by: Richard Schreiber <schreiber@rami.io>

* Review notes

---------

Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
Raphael Michel
2023-11-06 13:26:32 +01:00
committed by GitHub
parent 3d68c83907
commit 3af2342d7b
15 changed files with 235 additions and 54 deletions

View File

@@ -0,0 +1,22 @@
# Generated by Django 4.2.4 on 2023-10-30 11:50
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("pretixbase", "0248_item_free_price_suggestion"),
]
operations = [
migrations.AddField(
model_name="item",
name="hidden_if_item_available",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="pretixbase.item",
),
),
]

View File

@@ -857,6 +857,10 @@ class Event(EventMixin, LoggedModel):
v.item = i
v.save(force_insert=True)
for i in self.items.filter(hidden_if_item_available__isnull=False):
i.hidden_if_item_available = item_map[i.hidden_if_item_available_id]
i.save()
for imv in ItemMetaValue.objects.filter(item__event=other):
imv.pk = None
imv.property = item_meta_properties_map[imv.property_id]

View File

@@ -494,13 +494,24 @@ class Item(LoggedModel):
'Quota',
null=True, blank=True,
on_delete=models.SET_NULL,
verbose_name=_("Only show after sellout of"),
verbose_name=pgettext_lazy("hidden_if_available_legacy", "Only show after sellout of"),
help_text=_("If you select a quota here, this product will only be shown when that quota is "
"unavailable. If combined with the option to hide sold-out products, this allows you to "
"swap out products for more expensive ones once they are sold out. There might be a short period "
"in which both products are visible while all tickets in the referenced quota are reserved, "
"but not yet sold.")
)
hidden_if_item_available = models.ForeignKey(
'Item',
null=True, blank=True,
on_delete=models.SET_NULL,
verbose_name=_("Only show after sellout of"),
help_text=_("If you select a product here, this product will only be shown when that product is "
"sold out. If combined with the option to hide sold-out products, this allows you to "
"swap out products for more expensive ones once the cheaper option is sold out. There might "
"be a short period in which both products are visible while all tickets of the referenced "
"product are reserved, but not yet sold.")
)
require_voucher = models.BooleanField(
verbose_name=_('This product can only be bought using a voucher.'),
default=False,