mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24: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:
@@ -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")),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user