diff --git a/src/pretix/base/migrations/0005_auto_20151206_1652.py b/src/pretix/base/migrations/0005_auto_20151206_1652.py
new file mode 100644
index 0000000000..9992623452
--- /dev/null
+++ b/src/pretix/base/migrations/0005_auto_20151206_1652.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('pretixbase', '0004_auto_20151024_0848'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='item',
+ name='available_from',
+ field=models.DateTimeField(null=True, help_text='This product will not be sold before the given date.', blank=True, verbose_name='Available from'),
+ ),
+ migrations.AddField(
+ model_name='item',
+ name='available_until',
+ field=models.DateTimeField(null=True, help_text='This product will not be sold after the given date.', blank=True, verbose_name='Available to'),
+ ),
+ ]
diff --git a/src/pretix/base/models/items.py b/src/pretix/base/models/items.py
index d8ecca922e..ec707375a5 100644
--- a/src/pretix/base/models/items.py
+++ b/src/pretix/base/models/items.py
@@ -1,6 +1,5 @@
import sys
from datetime import datetime
-from decimal import Decimal
from itertools import product
from django.db import models
@@ -8,7 +7,7 @@ from django.db.models import Q, Case, Count, Sum, When
from django.utils.functional import cached_property
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
-from typing import List, Tuple, Union
+from typing import List, Tuple
from versions.models import VersionedForeignKey, VersionedManyToManyField
from pretix.base.i18n import I18nCharField, I18nTextField
@@ -98,6 +97,10 @@ class Item(Versionable):
:type admission: bool
:param picture: A product picture to be shown next to the product description.
:type picture: File
+ :param available_from: The date this product goes on sale
+ :type available_from: datetime
+ :param available_until: The date until when the product is on sale
+ :type available_until: datetime
"""
@@ -152,6 +155,16 @@ class Item(Versionable):
null=True, blank=True,
upload_to=itempicture_upload_to
)
+ available_from = models.DateTimeField(
+ verbose_name=_("Available from"),
+ null=True, blank=True,
+ help_text=_('This product will not be sold before the given date.')
+ )
+ available_until = models.DateTimeField(
+ verbose_name=_("Available until"),
+ null=True, blank=True,
+ help_text=_('This product will not be sold after the given date.')
+ )
class Meta:
verbose_name = _("Product")
@@ -171,6 +184,19 @@ class Item(Versionable):
if self.event:
self.event.get_cache().clear()
+ def is_available(self) -> bool:
+ """
+ Returns whether this item is available according to its ``active`` flag
+ and its ``available_from`` and ``available_until`` fields
+ """
+ if not self.active:
+ return False
+ if self.available_from and self.available_from > now():
+ return False
+ if self.available_until and self.available_until < now():
+ return False
+ return True
+
def get_all_variations(self, use_cache: bool=False) -> List[VariationDict]:
"""
This method returns a list containing all variations of this
diff --git a/src/pretix/base/services/cart.py b/src/pretix/base/services/cart.py
index b7b6ca6de2..c19aaa462b 100644
--- a/src/pretix/base/services/cart.py
+++ b/src/pretix/base/services/cart.py
@@ -93,7 +93,7 @@ def _add_items(event: Event, items: List[Tuple[str, Optional[str], int]],
# Fetch all quotas. If there are no quotas, this item is not allowed to be sold.
quotas = list(item.quotas.all()) if variation is None else list(variation.quotas.all())
- if len(quotas) == 0 or not item.active:
+ if len(quotas) == 0 or not item.is_available():
err = err or error_messages['unavailable']
continue
diff --git a/src/pretix/control/forms/item.py b/src/pretix/control/forms/item.py
index f991c7f52d..df2c762c2f 100644
--- a/src/pretix/control/forms/item.py
+++ b/src/pretix/control/forms/item.py
@@ -137,6 +137,8 @@ class ItemFormGeneral(VersionedModelForm):
'picture',
'default_price',
'tax_rate',
+ 'available_from',
+ 'available_until',
]
diff --git a/src/pretix/control/templates/pretixcontrol/item/index.html b/src/pretix/control/templates/pretixcontrol/item/index.html
index 3e6eb9c24f..1aa8fc1a68 100644
--- a/src/pretix/control/templates/pretixcontrol/item/index.html
+++ b/src/pretix/control/templates/pretixcontrol/item/index.html
@@ -18,6 +18,11 @@
{% bootstrap_field form.default_price layout="horizontal" %}
{% bootstrap_field form.tax_rate layout="horizontal" %}
+