TaxRules: Add internal_name and keep_gross_if_rate_changes (#2422)

Co-authored-by: ser8phin <eva.wolkwitz@gmx.de>
This commit is contained in:
Raphael Michel
2022-01-21 15:39:27 +01:00
committed by GitHub
parent c1344422a5
commit 6f0da5c2ca
16 changed files with 591 additions and 18 deletions

View File

@@ -28,6 +28,7 @@ from django_countries.fields import Country
from django_scopes import scope
from pretix.base.models import Event, InvoiceAddress, Organizer, TaxRule
from pretix.base.models.tax import TaxedPrice
@pytest.fixture
@@ -88,6 +89,13 @@ def test_reverse_charge_no_country(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -103,6 +111,13 @@ def test_reverse_charge_individual_same_country(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -118,6 +133,13 @@ def test_reverse_charge_individual_eu(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -133,6 +155,13 @@ def test_reverse_charge_individual_3rdc(event):
assert not tr.is_reverse_charge(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('100.00'),
net=Decimal('100.00'),
tax=Decimal('0.00'),
rate=Decimal('0.00'),
name='',
)
@pytest.mark.django_db
@@ -148,6 +177,13 @@ def test_reverse_charge_business_same_country(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -163,6 +199,13 @@ def test_reverse_charge_business_eu(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -178,6 +221,13 @@ def test_reverse_charge_business_3rdc(event):
assert not tr.is_reverse_charge(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('100.00'),
net=Decimal('100.00'),
tax=Decimal('0.00'),
rate=Decimal('0.00'),
name='',
)
@pytest.mark.django_db
@@ -195,6 +245,13 @@ def test_reverse_charge_valid_vat_id_business_same_country(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -212,6 +269,13 @@ def test_reverse_charge_valid_vat_id_business_eu(event):
assert tr.is_reverse_charge(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('100.00'),
net=Decimal('100.00'),
tax=Decimal('0.00'),
rate=Decimal('0.00'),
name='',
)
@pytest.mark.django_db
@@ -229,6 +293,13 @@ def test_reverse_charge_valid_vat_id_business_3rdc(event):
assert not tr.is_reverse_charge(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('100.00'),
net=Decimal('100.00'),
tax=Decimal('0.00'),
rate=Decimal('0.00'),
name='',
)
@pytest.mark.django_db
@@ -246,6 +317,13 @@ def test_reverse_charge_disabled(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -266,6 +344,13 @@ def test_custom_rules_override(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -287,6 +372,13 @@ def test_custom_rules_in_order(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -305,6 +397,13 @@ def test_custom_rules_any_country(event):
assert not tr.is_reverse_charge(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('100.00'),
net=Decimal('100.00'),
tax=Decimal('0.00'),
rate=Decimal('0.00'),
name='',
)
@pytest.mark.django_db
@@ -329,6 +428,13 @@ def test_custom_rules_eu_country(event):
)
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -347,6 +453,14 @@ def test_custom_rules_specific_country(event):
assert not tr.is_reverse_charge(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('100.00'),
net=Decimal('100.00'),
tax=Decimal('0.00'),
rate=Decimal('0.00'),
name='',
)
ia = InvoiceAddress(
is_business=True,
country=Country('DE')
@@ -354,6 +468,13 @@ def test_custom_rules_specific_country(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -372,6 +493,14 @@ def test_custom_rules_individual(event):
assert not tr.is_reverse_charge(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('100.00'),
net=Decimal('100.00'),
tax=Decimal('0.00'),
rate=Decimal('0.00'),
name='',
)
ia = InvoiceAddress(
is_business=True,
country=Country('DE')
@@ -379,6 +508,13 @@ def test_custom_rules_individual(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -397,6 +533,14 @@ def test_custom_rules_business(event):
assert not tr.is_reverse_charge(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('100.00'),
net=Decimal('100.00'),
tax=Decimal('0.00'),
rate=Decimal('0.00'),
name='',
)
ia = InvoiceAddress(
is_business=False,
country=Country('DE')
@@ -404,6 +548,13 @@ def test_custom_rules_business(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
@pytest.mark.django_db
@@ -422,6 +573,14 @@ def test_custom_rules_vat_id(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
ia = InvoiceAddress(
is_business=True,
country=Country('DE'),
@@ -431,6 +590,13 @@ def test_custom_rules_vat_id(event):
assert tr.is_reverse_charge(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('100.00'),
net=Decimal('100.00'),
tax=Decimal('0.00'),
rate=Decimal('0.00'),
name='',
)
@pytest.mark.django_db
@@ -449,6 +615,13 @@ def test_custom_rules_country_rate(event):
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
ia = InvoiceAddress(
is_business=True,
country=Country('DE'),
@@ -458,3 +631,79 @@ def test_custom_rules_country_rate(event):
assert tr.tax_rate_for(ia) == Decimal('100.00')
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('200.00'),
net=Decimal('100.00'),
tax=Decimal('100.00'),
rate=Decimal('100.00'),
name='',
)
@pytest.mark.django_db
def test_custom_rules_country_rate_keep_gross_if_rate_changes(event):
tr = TaxRule(
event=event,
rate=Decimal('10.00'), price_includes_tax=False,
keep_gross_if_rate_changes=True,
custom_rules=json.dumps([
{'country': 'EU', 'address_type': 'business_vat_id', 'action': 'vat', 'rate': '100.00'},
])
)
ia = InvoiceAddress(
is_business=True,
country=Country('DE')
)
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('100.00'),
tax=Decimal('10.00'),
rate=Decimal('10.00'),
name='',
)
ia = InvoiceAddress(
is_business=True,
country=Country('DE'),
vat_id='DE1234',
vat_id_validated=True
)
assert tr.tax_rate_for(ia) == Decimal('100.00')
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
gross=Decimal('110.00'),
net=Decimal('55.00'),
tax=Decimal('55.00'),
rate=Decimal('100.00'),
name='',
)
@pytest.mark.django_db
def test_custom_rules_country_rate_subtract_from_gross(event):
tr = TaxRule(
event=event,
rate=Decimal('10.00'), price_includes_tax=False,
custom_rules=json.dumps([
{'country': 'EU', 'address_type': 'business_vat_id', 'action': 'vat', 'rate': '100.00'},
])
)
ia = InvoiceAddress(
is_business=True,
country=Country('DE'),
vat_id='DE1234',
vat_id_validated=True
)
assert tr.tax_rate_for(ia) == Decimal('100.00')
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax(Decimal('100.00'), invoice_address=ia, subtract_from_gross=Decimal('20.00')) == TaxedPrice(
gross=Decimal('163.64'), # ((100 * 1.1) - 20) / (1 + 10%) * (1 + 100%)
net=Decimal('81.82'),
tax=Decimal('81.82'),
rate=Decimal('100.00'),
name='',
)