mirror of
https://github.com/pretix/pretix.git
synced 2026-05-07 15:34:02 +00:00
New data model for default tax rule and new options for cancellation fees (#4962)
* New data model for default tax rule * Remove misleading empty label when field is not optional * Allow to split cancellation fee * Fix API and tests * Update migration * Update src/tests/api/test_taxrules.py Co-authored-by: luelista <weller@rami.io> * Update src/tests/api/test_taxrules.py Co-authored-by: luelista <weller@rami.io> * Review note * Update src/pretix/base/models/tax.py Co-authored-by: luelista <weller@rami.io> * Flip API behaviour for default * Fix failing tests * Fix failing test * Split migration --------- Co-authored-by: luelista <weller@rami.io>
This commit is contained in:
@@ -439,8 +439,37 @@ def test_order_cancel_paid_keep_fee(client, env):
|
||||
o.payments.create(state=OrderPayment.PAYMENT_STATE_CONFIRMED, amount=o.total)
|
||||
o.status = Order.STATUS_PAID
|
||||
o.save()
|
||||
tr7 = o.event.tax_rules.create(rate=Decimal('7.00'))
|
||||
o.event.settings.tax_rate_default = tr7
|
||||
o.event.tax_rules.create(rate=Decimal('7.00'), default=True)
|
||||
client.login(email='dummy@dummy.dummy', password='dummy')
|
||||
client.get('/control/event/dummy/dummy/orders/FOO/transition?status=c')
|
||||
client.post('/control/event/dummy/dummy/orders/FOO/transition', {
|
||||
'status': 'c',
|
||||
'cancellation_fee': '6.00'
|
||||
})
|
||||
with scopes_disabled():
|
||||
o = Order.objects.get(id=env[2].id)
|
||||
assert not o.positions.exists()
|
||||
assert o.all_positions.exists()
|
||||
f = o.fees.get()
|
||||
assert f.fee_type == OrderFee.FEE_TYPE_CANCELLATION
|
||||
assert f.value == Decimal('6.00')
|
||||
assert f.tax_value == Decimal('0.00')
|
||||
assert f.tax_rate == Decimal('0.00')
|
||||
assert f.tax_rule is None
|
||||
assert o.status == Order.STATUS_PAID
|
||||
assert o.total == Decimal('6.00')
|
||||
assert o.pending_sum == Decimal('-8.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_order_cancel_paid_keep_fee_taxed(client, env):
|
||||
env[0].settings.tax_rule_cancellation = "default"
|
||||
with scopes_disabled():
|
||||
o = Order.objects.get(id=env[2].id)
|
||||
o.payments.create(state=OrderPayment.PAYMENT_STATE_CONFIRMED, amount=o.total)
|
||||
o.status = Order.STATUS_PAID
|
||||
o.save()
|
||||
tr7 = o.event.tax_rules.create(rate=Decimal('7.00'), default=True)
|
||||
client.login(email='dummy@dummy.dummy', password='dummy')
|
||||
client.get('/control/event/dummy/dummy/orders/FOO/transition?status=c')
|
||||
client.post('/control/event/dummy/dummy/orders/FOO/transition', {
|
||||
@@ -462,6 +491,50 @@ def test_order_cancel_paid_keep_fee(client, env):
|
||||
assert o.pending_sum == Decimal('-8.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_order_cancel_paid_keep_fee_tax_split(client, env):
|
||||
env[0].settings.tax_rule_cancellation = "split"
|
||||
with scopes_disabled():
|
||||
o = Order.objects.get(id=env[2].id)
|
||||
o.payments.create(state=OrderPayment.PAYMENT_STATE_CONFIRMED, amount=o.total)
|
||||
o.status = Order.STATUS_PAID
|
||||
o.save()
|
||||
tr7 = o.event.tax_rules.create(rate=Decimal('7.00'), default=False)
|
||||
tr19 = o.event.tax_rules.create(rate=Decimal('19.00'), default=True)
|
||||
op1 = o.positions.first()
|
||||
op1._calculate_tax(tax_rule=tr7)
|
||||
op1.save()
|
||||
op2 = o.all_positions.last()
|
||||
op2.canceled = False
|
||||
op2._calculate_tax(tax_rule=tr19)
|
||||
op2.save()
|
||||
client.login(email='dummy@dummy.dummy', password='dummy')
|
||||
client.get('/control/event/dummy/dummy/orders/FOO/transition?status=c')
|
||||
client.post('/control/event/dummy/dummy/orders/FOO/transition', {
|
||||
'status': 'c',
|
||||
'cancellation_fee': '6.00'
|
||||
})
|
||||
with scopes_disabled():
|
||||
o = Order.objects.get(id=env[2].id)
|
||||
assert not o.positions.exists()
|
||||
assert o.all_positions.exists()
|
||||
f = o.fees.order_by("-tax_rate")
|
||||
assert len(f) == 2
|
||||
assert f[0].fee_type == OrderFee.FEE_TYPE_CANCELLATION
|
||||
assert f[0].value == Decimal('3.00')
|
||||
assert f[0].tax_value == Decimal('0.48')
|
||||
assert f[0].tax_rate == Decimal('19')
|
||||
assert f[0].tax_rule == tr19
|
||||
assert f[1].fee_type == OrderFee.FEE_TYPE_CANCELLATION
|
||||
assert f[1].value == Decimal('3.00')
|
||||
assert f[1].tax_value == Decimal('0.20')
|
||||
assert f[1].tax_rate == Decimal('7')
|
||||
assert f[1].tax_rule == tr7
|
||||
assert o.status == Order.STATUS_PAID
|
||||
assert o.total == Decimal('6.00')
|
||||
assert o.pending_sum == Decimal('-8.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_order_cancel_pending_keep_fee(client, env):
|
||||
with scopes_disabled():
|
||||
|
||||
Reference in New Issue
Block a user