mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
Fixed #85 -- Fixed logic of time restrictions
This commit is contained in:
@@ -152,6 +152,19 @@ In our example, the implementation could look like this::
|
|||||||
|
|
||||||
# Walk through all variations we are asked for
|
# Walk through all variations we are asked for
|
||||||
for v in variations:
|
for v in variations:
|
||||||
|
var_restrictions = []
|
||||||
|
for restriction in restrictions:
|
||||||
|
applied_to = list(restriction.variations.current.all())
|
||||||
|
|
||||||
|
# Only take this restriction into consideration if it
|
||||||
|
# is directly applied to this variation or if the item
|
||||||
|
# has no variations
|
||||||
|
if v.empty() or ('variation' in v and v['variation'] in applied_to):
|
||||||
|
var_restrictions.append(restriction)
|
||||||
|
|
||||||
|
if not var_restrictions:
|
||||||
|
continue
|
||||||
|
|
||||||
# If this point is reached, there ARE time restrictions for this item
|
# If this point is reached, there ARE time restrictions for this item
|
||||||
# Therefore, it is only available inside one of the timeframes, but not
|
# Therefore, it is only available inside one of the timeframes, but not
|
||||||
# without any timeframe
|
# without any timeframe
|
||||||
@@ -175,15 +188,7 @@ In our example, the implementation could look like this::
|
|||||||
|
|
||||||
# Walk through all restriction objects applied to this item
|
# Walk through all restriction objects applied to this item
|
||||||
prices = []
|
prices = []
|
||||||
for restriction in restrictions:
|
for restriction in var_restrictions:
|
||||||
applied_to = list(restriction.variations.current.all())
|
|
||||||
|
|
||||||
# Only take this restriction into consideration if it
|
|
||||||
# is directly applied to this variation or if the item
|
|
||||||
# has no variations
|
|
||||||
if not v.empty() and ('variation' not in v or v['variation'] not in applied_to):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if restriction.timeframe_from <= now() <= restriction.timeframe_to:
|
if restriction.timeframe_from <= now() <= restriction.timeframe_to:
|
||||||
# Selling this item is currently possible
|
# Selling this item is currently possible
|
||||||
available = True
|
available = True
|
||||||
|
|||||||
@@ -1022,15 +1022,22 @@ class Item(Versionable):
|
|||||||
else:
|
else:
|
||||||
var['price'] = self.default_price
|
var['price'] = self.default_price
|
||||||
|
|
||||||
|
# It is possible, that *multiple* restriction plugins change the default price.
|
||||||
|
# In this case, the cheapest one wins. As soon as there is a restriction
|
||||||
|
# that changes the price, the default price has no effect.
|
||||||
|
|
||||||
newprice = None
|
newprice = None
|
||||||
for receiver, response in responses:
|
for receiver, response in responses:
|
||||||
if 'available' in response[i]:
|
if 'available' in response[i] and not response[i]['available']:
|
||||||
var['available'] &= response[i]['available']
|
var['available'] = False
|
||||||
|
break
|
||||||
if 'price' in response[i] and response[i]['price'] is not None \
|
if 'price' in response[i] and response[i]['price'] is not None \
|
||||||
and (newprice is None or response[i]['price'] < newprice):
|
and (newprice is None or response[i]['price'] < newprice):
|
||||||
newprice = response[i]['price']
|
newprice = response[i]['price']
|
||||||
var['price'] = newprice or var['price']
|
var['price'] = newprice or var['price']
|
||||||
|
|
||||||
|
variations = [var for var in variations if var['available']]
|
||||||
|
|
||||||
self._get_all_available_variations_cache = variations
|
self._get_all_available_variations_cache = variations
|
||||||
return variations
|
return variations
|
||||||
|
|
||||||
|
|||||||
@@ -56,9 +56,22 @@ def availability_handler(sender, **kwargs):
|
|||||||
|
|
||||||
# Walk through all variations we are asked for
|
# Walk through all variations we are asked for
|
||||||
for v in variations:
|
for v in variations:
|
||||||
|
var_restrictions = []
|
||||||
|
for restriction in restrictions:
|
||||||
|
applied_to = list(restriction.variations.current.all())
|
||||||
|
|
||||||
|
# Only take this restriction into consideration if it
|
||||||
|
# is directly applied to this variation or if the item
|
||||||
|
# has no variations
|
||||||
|
if v.empty() or ('variation' in v and v['variation'] in applied_to):
|
||||||
|
var_restrictions.append(restriction)
|
||||||
|
|
||||||
|
if not var_restrictions:
|
||||||
|
continue
|
||||||
|
|
||||||
# If this point is reached, there ARE time restrictions for this item
|
# If this point is reached, there ARE time restrictions for this item
|
||||||
# Therefore, it is only available inside one of the timeframes, but not
|
# Therefore, it is only available inside one of the timeframes, but not
|
||||||
# without any timeframe
|
# without any timeframe.
|
||||||
available = False
|
available = False
|
||||||
|
|
||||||
# Make up some unique key for this variation
|
# Make up some unique key for this variation
|
||||||
@@ -79,15 +92,7 @@ def availability_handler(sender, **kwargs):
|
|||||||
|
|
||||||
# Walk through all restriction objects applied to this item
|
# Walk through all restriction objects applied to this item
|
||||||
prices = []
|
prices = []
|
||||||
for restriction in restrictions:
|
for restriction in var_restrictions:
|
||||||
applied_to = list(restriction.variations.current.all())
|
|
||||||
|
|
||||||
# Only take this restriction into consideration if it
|
|
||||||
# is directly applied to this variation or if the item
|
|
||||||
# has no variations
|
|
||||||
if not v.empty() and ('variation' not in v or v['variation'] not in applied_to):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if restriction.timeframe_from <= now() <= restriction.timeframe_to:
|
if restriction.timeframe_from <= now() <= restriction.timeframe_to:
|
||||||
# Selling this item is currently possible
|
# Selling this item is currently possible
|
||||||
available = True
|
available = True
|
||||||
|
|||||||
Reference in New Issue
Block a user