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:
Raphael Michel
2025-06-30 16:47:09 +02:00
committed by GitHub
parent 090358833d
commit 14ed6982a5
34 changed files with 615 additions and 104 deletions

View File

@@ -27,8 +27,11 @@ from django.utils.timezone import now
from django_countries.fields import Country
from django_scopes import scope
from pretix.base.models import Event, InvoiceAddress, Organizer, TaxRule
from pretix.base.models import (
Event, InvoiceAddress, OrderFee, OrderPosition, Organizer, TaxRule,
)
from pretix.base.models.tax import TaxedPrice
from pretix.base.services.tax import split_fee_for_taxes
@pytest.fixture
@@ -962,3 +965,39 @@ def test_allow_negative(event):
price_includes_tax=True,
)
assert tr.tax(Decimal('-100.00')).gross == Decimal("-100.00")
@pytest.mark.django_db
def test_split_fees(event):
tr19 = TaxRule(rate=Decimal("19.00"), pk=1)
tr7 = TaxRule(rate=Decimal("7.00"), pk=2)
item = event.items.create(name="Budget Ticket", default_price=23)
op1 = OrderPosition(price=Decimal("11.90"), item=item)
op1._calculate_tax(tax_rule=tr19, invoice_address=InvoiceAddress())
op2 = OrderPosition(price=Decimal("10.70"), item=item)
op2._calculate_tax(tax_rule=tr7, invoice_address=InvoiceAddress())
of1 = OrderFee(value=Decimal("5.00"), fee_type=OrderFee.FEE_TYPE_SHIPPING)
of1._calculate_tax(tax_rule=tr7, invoice_address=InvoiceAddress())
# Example of a 10% service fee
assert split_fee_for_taxes([op1, op2], Decimal("2.26"), event) == [
(tr7, Decimal("1.07")),
(tr19, Decimal("1.19")),
]
# Example of a full cancellation fee
assert split_fee_for_taxes([op1, op2], Decimal("22.60"), event) == [
(tr7, Decimal("10.70")),
(tr19, Decimal("11.90")),
]
assert split_fee_for_taxes([op1, op2, of1], Decimal("27.60"), event) == [
(tr7, Decimal("15.70")),
(tr19, Decimal("11.90")),
]
# Example that rounding always is done with benefit to the highest tax rate
assert split_fee_for_taxes([op1, op2], Decimal("0.03"), event) == [
(tr7, Decimal("0.01")),
(tr19, Decimal("0.02")),
]