mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Add sub-events and relative date settings (#503)
* Data model * little crud * SubEventItemForm etc * Drop SubEventItem.active, quota editor * Fix failing tests * First frontend stuff * Addons form stuff * Quota calculation * net price display on EventIndex * Add tests, solve some bugs * Correct quota selection in more places, consolidate pricing logic * Fix failing quota tests * Fix TypeError * Add tests for checkout * Fixed a bug in QuotaForm * Prevent immutable cart if a quota was removed from an item * Add tests for pricing * Handle waiting list * Filter in check-in list * Fixed import lost in rebase * Fix waiting list widget * Voucher management * Voucher redemption * Fix broken tests * Add subevents to OrderChangeManager * Create a subevent during event creation * Fix bulk voucher creation * Introduce subevent.active * Copy from for subevents * Show active in list * ICal download for subevents * Check start and end of presale * Failing tests / show cart logic * Test * Rebase migrations * REST API integration of sub-events * Integrate quota calculation into the traditional quota form * Make subevent argument to add_position optional * Log-display foo * pretixdroid and subevents * Filter by subevent * Add more tests * Some mor tests * Rebase fixes * More tests * Relative dates * Restrict selection in relative datetime widgets * Filter subevent list * Re-label has_subevents * Rebase fixes, subevents in calendar view * Performance and caching issues * Refactor calendar templates * Permission tests * Calendar fixes and month selection * subevent selection * Rename subevents to dates * Add tests for calendar views
This commit is contained in:
195
src/tests/base/test_pricing.py
Normal file
195
src/tests/base/test_pricing.py
Normal file
@@ -0,0 +1,195 @@
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
from django.utils.timezone import now
|
||||
|
||||
from pretix.base.models import Event, Organizer
|
||||
from pretix.base.models.items import SubEventItem, SubEventItemVariation
|
||||
from pretix.base.services.pricing import get_price
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def event():
|
||||
o = Organizer.objects.create(name='Dummy', slug='dummy')
|
||||
event = Event.objects.create(
|
||||
organizer=o, name='Dummy', slug='dummy',
|
||||
date_from=now()
|
||||
)
|
||||
return event
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def item(event):
|
||||
return event.items.create(name='Ticket', default_price=Decimal('23.00'))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def variation(item):
|
||||
return item.variations.create(value='Premium', default_price=None)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def voucher(event):
|
||||
return event.vouchers.create()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def subevent(event):
|
||||
event.has_subevents = True
|
||||
event.save()
|
||||
return event.subevents.create(name='Foobar', date_from=now())
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_base_item_default(item):
|
||||
assert get_price(item) == Decimal('23.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_base_item_subevent_no_entry(item, subevent):
|
||||
assert get_price(item, subevent=subevent) == Decimal('23.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_base_item_subevent_no_override(item, subevent):
|
||||
SubEventItem.objects.create(item=item, subevent=subevent, price=None)
|
||||
assert get_price(item, subevent=subevent) == Decimal('23.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_base_item_subevent_override(item, subevent):
|
||||
SubEventItem.objects.create(item=item, subevent=subevent, price=Decimal('24.00'))
|
||||
assert get_price(item, subevent=subevent) == Decimal('24.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_variation_with_default_item_price(item, variation):
|
||||
assert get_price(item, variation=variation) == Decimal('23.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_variation_with_specific_price(item, variation):
|
||||
variation.default_price = Decimal('24.00')
|
||||
assert get_price(item, variation=variation) == Decimal('24.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_variation_with_default_subevent_and_default_price(item, subevent, variation):
|
||||
SubEventItemVariation.objects.create(variation=variation, subevent=subevent, price=None)
|
||||
assert get_price(item, variation=variation, subevent=subevent) == Decimal('23.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_variation_with_subevent_and_default_price(item, subevent, variation):
|
||||
SubEventItemVariation.objects.create(variation=variation, subevent=subevent, price=Decimal('24.00'))
|
||||
assert get_price(item, variation=variation, subevent=subevent) == Decimal('24.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_variation_with_no_subevent_and_specific_price(item, subevent, variation):
|
||||
variation.default_price = Decimal('24.00')
|
||||
assert get_price(item, variation=variation, subevent=subevent) == Decimal('24.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_variation_with_default_subevent_and_specific_price(item, subevent, variation):
|
||||
variation.default_price = Decimal('24.00')
|
||||
SubEventItemVariation.objects.create(variation=variation, subevent=subevent, price=None)
|
||||
assert get_price(item, variation=variation, subevent=subevent) == Decimal('24.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_variation_with_subevent_and_specific_price(item, subevent, variation):
|
||||
variation.default_price = Decimal('24.00')
|
||||
SubEventItemVariation.objects.create(variation=variation, subevent=subevent, price=Decimal('26.00'))
|
||||
assert get_price(item, variation=variation, subevent=subevent) == Decimal('26.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_voucher_no_override(item, subevent, voucher):
|
||||
assert get_price(item, subevent=subevent, voucher=voucher) == Decimal('23.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_voucher_set_price(item, subevent, voucher):
|
||||
voucher.price_mode = 'set'
|
||||
voucher.value = Decimal('12.00')
|
||||
assert get_price(item, subevent=subevent, voucher=voucher) == Decimal('12.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_voucher_subtract(item, subevent, voucher):
|
||||
voucher.price_mode = 'subtract'
|
||||
voucher.value = Decimal('12.00')
|
||||
assert get_price(item, subevent=subevent, voucher=voucher) == Decimal('11.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_voucher_percent(item, subevent, voucher):
|
||||
voucher.price_mode = 'percent'
|
||||
voucher.value = Decimal('10.00')
|
||||
assert get_price(item, subevent=subevent, voucher=voucher) == Decimal('20.70')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_free_price_ignored_if_disabled(item):
|
||||
assert get_price(item, custom_price=Decimal('42.00')) == Decimal('23.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_free_price_ignored_if_lower(item):
|
||||
item.free_price = True
|
||||
assert get_price(item, custom_price=Decimal('12.00')) == Decimal('23.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_free_price_ignored_if_lower_than_voucher(item, voucher):
|
||||
voucher.price_mode = 'set'
|
||||
voucher.value = Decimal('50.00')
|
||||
assert get_price(item, voucher=voucher, custom_price=Decimal('40.00')) == Decimal('50.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_free_price_ignored_if_lower_than_subevent(item, subevent):
|
||||
item.free_price = True
|
||||
SubEventItem.objects.create(item=item, subevent=subevent, price=Decimal('50.00'))
|
||||
assert get_price(item, subevent=subevent, custom_price=Decimal('40.00')) == Decimal('50.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_free_price_ignored_if_lower_than_variation(item, variation):
|
||||
variation.default_price = Decimal('50.00')
|
||||
item.free_price = True
|
||||
assert get_price(item, variation=variation, custom_price=Decimal('40.00')) == Decimal('50.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_free_price_accepted(item):
|
||||
item.free_price = True
|
||||
assert get_price(item, custom_price=Decimal('42.00')) == Decimal('42.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_free_price_string(item):
|
||||
item.free_price = True
|
||||
assert get_price(item, custom_price='42,00') == Decimal('42.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_free_price_float(item):
|
||||
item.free_price = True
|
||||
assert get_price(item, custom_price=42.00) == Decimal('42.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_free_price_limit(item):
|
||||
item.free_price = True
|
||||
with pytest.raises(ValueError):
|
||||
get_price(item, custom_price=Decimal('200000000'))
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_free_price_net(item):
|
||||
item.free_price = True
|
||||
item.tax_rate = 19
|
||||
assert get_price(item, custom_price=Decimal('100.00'), custom_price_is_net=True) == Decimal('119.00')
|
||||
Reference in New Issue
Block a user