forked from CGM_Public/pretix_original
TaxRules: Add internal_name and keep_gross_if_rate_changes (#2422)
Co-authored-by: ser8phin <eva.wolkwitz@gmx.de>
This commit is contained in:
@@ -27,6 +27,8 @@ from django_scopes import scopes_disabled
|
||||
from pretix.base.models import TaxRule
|
||||
|
||||
TEST_TAXRULE_RES = {
|
||||
'internal_name': None,
|
||||
'keep_gross_if_rate_changes': False,
|
||||
'name': {'en': 'VAT'},
|
||||
'rate': '19.00',
|
||||
'price_includes_tax': True,
|
||||
|
||||
@@ -26,6 +26,7 @@ import pytest
|
||||
from django.utils.timezone import now
|
||||
from django_countries.fields import Country
|
||||
|
||||
from pretix.base.decimal import round_decimal
|
||||
from pretix.base.models import Event, InvoiceAddress, Organizer
|
||||
from pretix.base.models.items import SubEventItem, SubEventItemVariation
|
||||
from pretix.base.services.pricing import get_price
|
||||
@@ -379,3 +380,77 @@ def test_country_specific_rule_gross_based(item):
|
||||
country=Country('BE')
|
||||
)
|
||||
assert get_price(item, invoice_address=ia).gross == Decimal('168.06')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_country_specific_rule_net_based_but_keep_gross_if_rate_changes(item):
|
||||
item.default_price = Decimal('100.00')
|
||||
item.tax_rule = item.event.tax_rules.create(
|
||||
rate=Decimal('19.00'), price_includes_tax=False, keep_gross_if_rate_changes=True,
|
||||
custom_rules=json.dumps([
|
||||
{'country': 'BE', 'address_type': '', 'action': 'vat', 'rate': '100.00'}
|
||||
])
|
||||
)
|
||||
ia = InvoiceAddress(
|
||||
is_business=True, vat_id="EU1234", vat_id_validated=True,
|
||||
country=Country('BE')
|
||||
)
|
||||
p = get_price(item, invoice_address=ia)
|
||||
assert p.gross == Decimal('119.00')
|
||||
assert p.rate == Decimal('100.00')
|
||||
assert p.tax == Decimal('59.50')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_country_specific_rule_net_based_subtract_bundled(item):
|
||||
item.default_price = Decimal('100.00')
|
||||
item.tax_rule = item.event.tax_rules.create(
|
||||
rate=Decimal('19.00'), price_includes_tax=False,
|
||||
custom_rules=json.dumps([
|
||||
{'country': 'BE', 'address_type': '', 'action': 'vat', 'rate': '100.00'}
|
||||
])
|
||||
)
|
||||
ia = InvoiceAddress(
|
||||
is_business=True, vat_id="EU1234", vat_id_validated=True,
|
||||
country=Country('BE')
|
||||
)
|
||||
assert get_price(item, invoice_address=ia, bundled_sum=Decimal('20.00')).gross == (
|
||||
round_decimal((Decimal('119.00') - Decimal('20.00')) / Decimal('1.19')) * Decimal('2')
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_country_specific_rule_gross_based_subtract_bundled(item):
|
||||
item.default_price = Decimal('100.00')
|
||||
item.tax_rule = item.event.tax_rules.create(
|
||||
rate=Decimal('19.00'), price_includes_tax=True,
|
||||
custom_rules=json.dumps([
|
||||
{'country': 'BE', 'address_type': '', 'action': 'vat', 'rate': '100.00'}
|
||||
])
|
||||
)
|
||||
ia = InvoiceAddress(
|
||||
is_business=True, vat_id="EU1234", vat_id_validated=True,
|
||||
country=Country('BE')
|
||||
)
|
||||
assert get_price(item, invoice_address=ia, bundled_sum=Decimal('20.00')).gross == (
|
||||
round_decimal((Decimal('100.00') - Decimal('20.00')) / Decimal('1.19')) * Decimal('2')
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_country_specific_rule_net_based_but_keep_gross_if_rate_changes_subtract_bundled(item):
|
||||
item.default_price = Decimal('100.00')
|
||||
item.tax_rule = item.event.tax_rules.create(
|
||||
rate=Decimal('19.00'), price_includes_tax=False, keep_gross_if_rate_changes=True,
|
||||
custom_rules=json.dumps([
|
||||
{'country': 'BE', 'address_type': '', 'action': 'vat', 'rate': '100.00'}
|
||||
])
|
||||
)
|
||||
ia = InvoiceAddress(
|
||||
is_business=True, vat_id="EU1234", vat_id_validated=True,
|
||||
country=Country('BE')
|
||||
)
|
||||
p = get_price(item, invoice_address=ia, bundled_sum=Decimal('20.00'))
|
||||
assert p.gross == Decimal('99.00')
|
||||
assert p.rate == Decimal('100.00')
|
||||
assert p.tax == Decimal('49.50')
|
||||
|
||||
@@ -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='',
|
||||
)
|
||||
|
||||
@@ -3518,6 +3518,39 @@ class CartBundleTest(CartTestMixin, TestCase):
|
||||
assert a.tax_rate == Decimal('0.00')
|
||||
assert not a.includes_tax
|
||||
|
||||
@classscope(attr='orga')
|
||||
def test_reverse_charge_bundled_add_keep_gross_price(self):
|
||||
ia = InvoiceAddress.objects.create(
|
||||
is_business=True, vat_id='ATU1234567', vat_id_validated=True,
|
||||
country=Country('AT')
|
||||
)
|
||||
tr19 = self.event.tax_rules.create(name='VAT', rate=Decimal('19.00'))
|
||||
tr7 = self.event.tax_rules.create(name='VAT', rate=Decimal('7.00'), eu_reverse_charge=True, home_country=Country('DE'),
|
||||
keep_gross_if_rate_changes=True)
|
||||
self.ticket.tax_rule = tr19
|
||||
self.ticket.save()
|
||||
self.trans.tax_rule = tr7
|
||||
self.trans.save()
|
||||
|
||||
self.cm.invoice_address = ia
|
||||
self.cm.add_new_items([
|
||||
{
|
||||
'item': self.ticket.pk,
|
||||
'variation': None,
|
||||
'count': 1
|
||||
}
|
||||
])
|
||||
self.cm.commit()
|
||||
|
||||
cp = CartPosition.objects.filter(addon_to__isnull=True).get()
|
||||
a = CartPosition.objects.filter(addon_to__isnull=False).get()
|
||||
assert cp.price == Decimal('21.50')
|
||||
assert cp.tax_rate == Decimal('19.00')
|
||||
assert cp.includes_tax
|
||||
assert a.price == Decimal('1.50')
|
||||
assert a.tax_rate == Decimal('0.00')
|
||||
assert not a.includes_tax
|
||||
|
||||
@classscope(attr='orga')
|
||||
def test_reverse_charge_bundled_add(self):
|
||||
ia = InvoiceAddress.objects.create(
|
||||
|
||||
@@ -351,6 +351,42 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
|
||||
ia = InvoiceAddress.objects.get(pk=self.client.session['carts'][self.session_key].get('invoice_address'))
|
||||
assert not ia.vat_id_validated
|
||||
|
||||
def test_reverse_charge_keep_gross(self):
|
||||
self.tr19.eu_reverse_charge = True
|
||||
self.tr19.keep_gross_if_rate_changes = True
|
||||
self.tr19.home_country = Country('DE')
|
||||
self.tr19.save()
|
||||
self.event.settings.invoice_address_vatid = True
|
||||
|
||||
with scopes_disabled():
|
||||
cr1 = CartPosition.objects.create(
|
||||
event=self.event, cart_id=self.session_key, item=self.ticket,
|
||||
price=23, expires=now() + timedelta(minutes=10)
|
||||
)
|
||||
|
||||
with mock.patch('vat_moss.id.validate') as mock_validate:
|
||||
mock_validate.return_value = ('AT', 'AT123456', 'Foo')
|
||||
self.client.post('/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug), {
|
||||
'is_business': 'business',
|
||||
'company': 'Foo',
|
||||
'name': 'Bar',
|
||||
'street': 'Baz',
|
||||
'zipcode': '12345',
|
||||
'city': 'Here',
|
||||
'country': 'AT',
|
||||
'vat_id': 'AT123456',
|
||||
'email': 'admin@localhost'
|
||||
}, follow=True)
|
||||
|
||||
cr1.refresh_from_db()
|
||||
assert cr1.price == Decimal('23.00')
|
||||
assert cr1.tax_rate == Decimal('0.00')
|
||||
assert cr1.tax_value == Decimal('0.00')
|
||||
|
||||
with scopes_disabled():
|
||||
ia = InvoiceAddress.objects.get(pk=self.client.session['carts'][self.session_key].get('invoice_address'))
|
||||
assert ia.vat_id_validated
|
||||
|
||||
def test_custom_tax_rules(self):
|
||||
self.tr19.custom_rules = json.dumps([
|
||||
{'country': 'AT', 'address_type': 'business_vat_id', 'action': 'reverse'},
|
||||
@@ -585,6 +621,72 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
|
||||
cr = CartPosition.objects.get(cart_id=self.session_key)
|
||||
assert cr.price == Decimal('21.26')
|
||||
|
||||
def test_free_price_net_price_reverse_charge_keep_gross(self):
|
||||
# This is an end-to-end test of a very confusing case in which the event is set to
|
||||
# "show net prices" but the tax rate is set to "keep gross if rate changes" in
|
||||
# combination of free prices.
|
||||
# This means the user will be greeted with a display price of "23 EUR + VAT". If they
|
||||
# then adjust the price to pay more, e.g. "40 EUR", it will be interpreted as a net
|
||||
# value (since the event is set to shown net values). The cart position is therefore
|
||||
# created with a gross price of 47.60 EUR. Then, the user enters their invoice address, which
|
||||
# triggers reverse charge. The tax is now removed, but since the tax rule is set to
|
||||
# keep the gross price the same, the user will still need to pay 47.60 EUR (incl 0% VAT),
|
||||
# instead of the 40 EUR the maybe wanted in the first place.
|
||||
# While confusing, this behaviour is technically correct and the correct answer to anyone
|
||||
# complaining about this is "do not turn display_net_prices and keep_gross_if_rate_changes
|
||||
# on at the same time" (display_net_prices only makes sense if you're targeting a B2B
|
||||
# audience in which case keep_gross_if_rate_changes is useless or even harmful).
|
||||
self.event.settings.display_net_prices = True
|
||||
self.ticket.free_price = True
|
||||
self.ticket.save()
|
||||
self.tr19.eu_reverse_charge = True
|
||||
self.tr19.keep_gross_if_rate_changes = True
|
||||
self.tr19.price_includes_tax = False
|
||||
self.tr19.home_country = Country('DE')
|
||||
self.tr19.save()
|
||||
self.event.settings.invoice_address_vatid = True
|
||||
|
||||
response = self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
|
||||
'item_%d' % self.ticket.id: '1',
|
||||
'price_%d' % self.ticket.id: '40.00',
|
||||
}, follow=True)
|
||||
self.assertRedirects(response, '/%s/%s/?require_cookie=true' % (self.orga.slug, self.event.slug),
|
||||
target_status_code=200)
|
||||
|
||||
with scopes_disabled():
|
||||
cr1 = CartPosition.objects.get()
|
||||
assert cr1.price == Decimal('47.60')
|
||||
assert cr1.tax_rate == Decimal('19.00')
|
||||
|
||||
with mock.patch('vat_moss.id.validate') as mock_validate:
|
||||
mock_validate.return_value = ('AT', 'AT123456', 'Foo')
|
||||
self.client.post('/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug), {
|
||||
'is_business': 'business',
|
||||
'company': 'Foo',
|
||||
'name': 'Bar',
|
||||
'street': 'Baz',
|
||||
'zipcode': '12345',
|
||||
'city': 'Here',
|
||||
'country': 'AT',
|
||||
'vat_id': 'AT123456',
|
||||
'email': 'admin@localhost'
|
||||
}, follow=True)
|
||||
|
||||
cr1.refresh_from_db()
|
||||
assert cr1.price == Decimal('47.60')
|
||||
assert cr1.tax_rate == Decimal('0.00')
|
||||
|
||||
self._set_session('payment', 'banktransfer')
|
||||
|
||||
response = self.client.post('/%s/%s/checkout/confirm/' % (self.orga.slug, self.event.slug), follow=True)
|
||||
doc = BeautifulSoup(response.content.decode(), "lxml")
|
||||
self.assertEqual(len(doc.select(".thank-you")), 1)
|
||||
with scopes_disabled():
|
||||
op = OrderPosition.objects.get()
|
||||
self.assertEqual(op.price, Decimal('47.60'))
|
||||
self.assertEqual(op.tax_value, Decimal('0.00'))
|
||||
self.assertEqual(op.tax_rate, Decimal('0.00'))
|
||||
|
||||
def test_question_file_upload(self):
|
||||
with scopes_disabled():
|
||||
q1 = Question.objects.create(
|
||||
@@ -1876,6 +1978,46 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
|
||||
cr1 = CartPosition.objects.get(id=cr1.id)
|
||||
self.assertEqual(cr1.price, round_decimal(Decimal('24.00') / Decimal('1.19')))
|
||||
|
||||
def test_confirm_price_changed_reverse_charge_keep_gross(self):
|
||||
self._enable_reverse_charge()
|
||||
self.tr19.keep_gross_if_rate_changes = True
|
||||
self.tr19.save()
|
||||
self.ticket.default_price = 24
|
||||
self.ticket.save()
|
||||
with scopes_disabled():
|
||||
cr1 = CartPosition.objects.create(
|
||||
event=self.event, cart_id=self.session_key, item=self.ticket,
|
||||
price=23, expires=now() - timedelta(minutes=10)
|
||||
)
|
||||
self._set_session('payment', 'banktransfer')
|
||||
|
||||
response = self.client.post('/%s/%s/checkout/confirm/' % (self.orga.slug, self.event.slug), follow=True)
|
||||
doc = BeautifulSoup(response.content.decode(), "lxml")
|
||||
self.assertEqual(len(doc.select(".alert-danger")), 1)
|
||||
with scopes_disabled():
|
||||
cr1 = CartPosition.objects.get(id=cr1.id)
|
||||
self.assertEqual(cr1.price, Decimal('24.00'))
|
||||
|
||||
def test_confirm_price_not_changed_reverse_charge_keep_gross(self):
|
||||
self._enable_reverse_charge()
|
||||
self.tr19.keep_gross_if_rate_changes = True
|
||||
self.tr19.save()
|
||||
with scopes_disabled():
|
||||
CartPosition.objects.create(
|
||||
event=self.event, cart_id=self.session_key, item=self.ticket,
|
||||
price=23, expires=now() - timedelta(minutes=10)
|
||||
)
|
||||
self._set_session('payment', 'banktransfer')
|
||||
|
||||
response = self.client.post('/%s/%s/checkout/confirm/' % (self.orga.slug, self.event.slug), follow=True)
|
||||
doc = BeautifulSoup(response.content.decode(), "lxml")
|
||||
self.assertEqual(len(doc.select(".thank-you")), 1)
|
||||
with scopes_disabled():
|
||||
op = OrderPosition.objects.get()
|
||||
self.assertEqual(op.price, Decimal('23.00'))
|
||||
self.assertEqual(op.tax_value, Decimal('0.00'))
|
||||
self.assertEqual(op.tax_rate, Decimal('0.00'))
|
||||
|
||||
def test_confirm_price_changed(self):
|
||||
self.ticket.default_price = 24
|
||||
self.ticket.save()
|
||||
|
||||
Reference in New Issue
Block a user