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:
@@ -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