Allow country specific tax rules (#1714)

This commit is contained in:
Raphael Michel
2020-07-08 15:00:13 +02:00
committed by GitHub
parent 1c9a1b5e02
commit 6e9d921af6
20 changed files with 716 additions and 161 deletions

View File

@@ -3394,6 +3394,38 @@ def test_order_create_auto_pricing_reverse_charge(token_client, organizer, event
assert o.total == Decimal('19.58')
@pytest.mark.django_db
def test_order_create_auto_pricing_country_rate(token_client, organizer, event, item, quota, question, taxrule):
taxrule.eu_reverse_charge = True
taxrule.custom_rules = json.dumps([
{'country': 'FR', 'address_type': '', 'action': 'vat', 'rate': '100.00'}
])
taxrule.save()
item.tax_rule = taxrule
item.save()
res = copy.deepcopy(ORDER_CREATE_PAYLOAD)
res['positions'][0]['item'] = item.pk
res['positions'][0]['answers'][0]['question'] = question.pk
res['invoice_address']['country'] = 'FR'
res['invoice_address']['is_business'] = True
res['invoice_address']['vat_id'] = 'FR12345'
res['invoice_address']['vat_id_validated'] = True
del res['positions'][0]['price']
resp = token_client.post(
'/api/v1/organizers/{}/events/{}/orders/'.format(
organizer.slug, event.slug
), format='json', data=res
)
assert resp.status_code == 201
with scopes_disabled():
o = Order.objects.get(code=resp.data['code'])
p = o.positions.first()
assert p.price == Decimal('38.66')
assert p.tax_rate == Decimal('100.00')
assert p.tax_value == Decimal('19.33')
assert o.total == Decimal('38.91')
@pytest.mark.django_db
def test_order_create_auto_pricing_reverse_charge_require_valid_vatid(token_client, organizer, event, item, quota,
question, taxrule):

View File

@@ -1,3 +1,4 @@
import json
from datetime import datetime, timedelta
from decimal import Decimal
@@ -1442,6 +1443,68 @@ class OrderChangeManagerTests(TestCase):
self.ocm.commit()
assert self.order.invoices.count() == 1
@classscope(attr='o')
def test_recalculate_country_rate(self):
self.event.settings.set('tax_rate_default', self.tr19.pk)
prov = self.ocm._get_payment_provider()
prov.settings.set('_fee_abs', Decimal('0.30'))
self.ocm._recalculate_total_and_payment_fee()
assert self.order.total == Decimal('46.30')
fee = self.order.fees.get(fee_type=OrderFee.FEE_TYPE_PAYMENT)
assert fee.value == prov.calculate_fee(self.order.total)
assert fee.tax_rate == Decimal('19.00')
assert fee.tax_value == Decimal('0.05')
self.ocm = OrderChangeManager(self.order, None)
self._enable_reverse_charge()
self.tr7.custom_rules = json.dumps([
{'country': 'AT', 'address_type': '', 'action': 'vat', 'rate': '100.00'}
])
self.tr7.save()
self.ocm.recalculate_taxes(keep='net')
self.ocm.commit()
ops = list(self.order.positions.all())
for op in ops:
assert op.price == Decimal('43.00')
assert op.tax_value == Decimal('21.50')
assert op.tax_rate == Decimal('100.00')
assert self.order.total == Decimal('86.00') + fee.value
@classscope(attr='o')
def test_recalculate_country_rate_keep_gross(self):
self.event.settings.set('tax_rate_default', self.tr19.pk)
prov = self.ocm._get_payment_provider()
prov.settings.set('_fee_abs', Decimal('0.30'))
self.ocm._recalculate_total_and_payment_fee()
assert self.order.total == Decimal('46.30')
fee = self.order.fees.get(fee_type=OrderFee.FEE_TYPE_PAYMENT)
assert fee.value == prov.calculate_fee(self.order.total)
assert fee.tax_rate == Decimal('19.00')
assert fee.tax_value == Decimal('0.05')
self.ocm = OrderChangeManager(self.order, None)
self._enable_reverse_charge()
self.tr7.custom_rules = json.dumps([
{'country': 'AT', 'address_type': '', 'action': 'vat', 'rate': '100.00'}
])
self.tr7.save()
self.ocm.recalculate_taxes(keep='gross')
self.ocm.commit()
ops = list(self.order.positions.all())
for op in ops:
assert op.price == Decimal('23.00')
assert op.tax_value == Decimal('11.50')
assert op.tax_rate == Decimal('100.00')
assert self.order.total == Decimal('46.00') + fee.value
@classscope(attr='o')
def test_recalculate_reverse_charge(self):
self.event.settings.set('tax_rate_default', self.tr19.pk)
@@ -2305,6 +2368,27 @@ class OrderChangeManagerTests(TestCase):
assert nop.tax_rate == Decimal('0.00')
assert nop.tax_value == Decimal('0.00')
@classscope(attr='o')
def test_change_taxrate_to_country_specific(self):
self.tr19.eu_reverse_charge = True
self.tr19.custom_rules = json.dumps([
{'country': 'AT', 'address_type': '', 'action': 'vat', 'rate': '100.00'}
])
self.tr19.save()
InvoiceAddress.objects.create(
order=self.order, is_business=True, vat_id='ATU1234567', vat_id_validated=True,
country=Country('AT')
)
self.ocm.change_tax_rule(self.op1, self.tr19)
self.ocm.commit()
self.order.refresh_from_db()
nop = self.order.positions.first()
assert nop.price == Decimal('23.00')
assert nop.tax_rule == self.tr19
assert nop.tax_rate == Decimal('100.00')
assert nop.tax_value == Decimal('19.33')
@classscope(attr='o')
def test_change_taxrate_from_reverse_charge(self):
self.tr7.eu_reverse_charge = True

View File

@@ -1,3 +1,4 @@
import json
from decimal import Decimal
import pytest
@@ -325,3 +326,35 @@ def test_tax_reverse_charge_invalid_vat_id(item):
)
assert not item.tax_rule.is_reverse_charge(ia)
assert get_price(item, invoice_address=ia).gross == Decimal('119.00')
@pytest.mark.django_db
def test_country_specific_rule_net_based(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).gross == Decimal('200.00')
@pytest.mark.django_db
def test_country_specific_rule_gross_based(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).gross == Decimal('168.06')

View File

@@ -53,7 +53,7 @@ def test_reverse_charge_no_address(event):
rate=Decimal('10.00'), price_includes_tax=False
)
assert not tr.is_reverse_charge(None)
assert tr.tax_applicable(None)
assert tr._tax_applicable(None)
@pytest.mark.django_db
@@ -65,7 +65,8 @@ def test_reverse_charge_no_country(event):
ia = InvoiceAddress(
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -79,7 +80,8 @@ def test_reverse_charge_individual_same_country(event):
country=Country('DE')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -93,7 +95,8 @@ def test_reverse_charge_individual_eu(event):
country=Country('AT')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -107,7 +110,8 @@ def test_reverse_charge_individual_3rdc(event):
country=Country('US')
)
assert not tr.is_reverse_charge(ia)
assert not tr.tax_applicable(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
@pytest.mark.django_db
@@ -121,7 +125,8 @@ def test_reverse_charge_business_same_country(event):
country=Country('DE')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -135,7 +140,8 @@ def test_reverse_charge_business_eu(event):
country=Country('AT')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -149,7 +155,8 @@ def test_reverse_charge_business_3rdc(event):
country=Country('US')
)
assert not tr.is_reverse_charge(ia)
assert not tr.tax_applicable(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
@pytest.mark.django_db
@@ -165,7 +172,8 @@ def test_reverse_charge_valid_vat_id_business_same_country(event):
vat_id_validated=True
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -181,7 +189,8 @@ def test_reverse_charge_valid_vat_id_business_eu(event):
country=Country('AT')
)
assert tr.is_reverse_charge(ia)
assert not tr.tax_applicable(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
@pytest.mark.django_db
@@ -197,7 +206,8 @@ def test_reverse_charge_valid_vat_id_business_3rdc(event):
vat_id_validated=True
)
assert not tr.is_reverse_charge(ia)
assert not tr.tax_applicable(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
@pytest.mark.django_db
@@ -213,7 +223,8 @@ def test_reverse_charge_disabled(event):
country=Country('AT')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -232,7 +243,8 @@ def test_custom_rules_override(event):
country=Country('AT')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -252,7 +264,8 @@ def test_custom_rules_in_order(event):
country=Country('AT')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -269,7 +282,8 @@ def test_custom_rules_any_country(event):
country=Country('AT')
)
assert not tr.is_reverse_charge(ia)
assert not tr.tax_applicable(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
@pytest.mark.django_db
@@ -286,13 +300,14 @@ def test_custom_rules_eu_country(event):
country=Country('AT')
)
assert not tr.is_reverse_charge(ia)
assert not tr.tax_applicable(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
ia = InvoiceAddress(
is_business=True,
country=Country('US')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
@pytest.mark.django_db
@@ -309,13 +324,15 @@ def test_custom_rules_specific_country(event):
country=Country('AT')
)
assert not tr.is_reverse_charge(ia)
assert not tr.tax_applicable(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
ia = InvoiceAddress(
is_business=True,
country=Country('DE')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -332,13 +349,15 @@ def test_custom_rules_individual(event):
country=Country('AT')
)
assert not tr.is_reverse_charge(ia)
assert not tr.tax_applicable(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
ia = InvoiceAddress(
is_business=True,
country=Country('DE')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -355,13 +374,15 @@ def test_custom_rules_business(event):
country=Country('AT')
)
assert not tr.is_reverse_charge(ia)
assert not tr.tax_applicable(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
ia = InvoiceAddress(
is_business=False,
country=Country('DE')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
@pytest.mark.django_db
@@ -378,7 +399,8 @@ def test_custom_rules_vat_id(event):
country=Country('AT')
)
assert not tr.is_reverse_charge(ia)
assert tr.tax_applicable(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.00')
ia = InvoiceAddress(
is_business=True,
country=Country('DE'),
@@ -386,4 +408,32 @@ def test_custom_rules_vat_id(event):
vat_id_validated=True
)
assert tr.is_reverse_charge(ia)
assert not tr.tax_applicable(ia)
assert not tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('0.00')
@pytest.mark.django_db
def test_custom_rules_country_rate(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')
)
assert not tr.is_reverse_charge(ia)
assert tr._tax_applicable(ia)
assert tr.tax_rate_for(ia) == Decimal('10.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)

View File

@@ -1370,7 +1370,7 @@ class OrderChangeTests(SoupTest):
'add-INITIAL_FORMS': '0',
'add-MIN_NUM_FORMS': '0',
'add-MAX_NUM_FORMS': '100',
'other-recalculate_taxes': 'on',
'other-recalculate_taxes': 'net',
'op-{}-operation'.format(self.op1.pk): '',
'op-{}-operation'.format(self.op2.pk): '',
'op-{}-itemvar'.format(self.op2.pk): str(self.ticket.pk),
@@ -1386,6 +1386,42 @@ class OrderChangeTests(SoupTest):
assert op.tax_value == Decimal('0.00')
assert op.tax_rate == Decimal('0.00')
def test_recalculate_reverse_charge_keep_gross(self):
self.tr7.eu_reverse_charge = True
self.tr7.home_country = Country('DE')
self.tr7.save()
self.tr19.eu_reverse_charge = True
self.tr19.home_country = Country('DE')
self.tr19.save()
with scopes_disabled():
InvoiceAddress.objects.create(
order=self.order, is_business=True, vat_id='ATU1234567', vat_id_validated=True,
country=Country('AT')
)
self.client.post('/control/event/{}/{}/orders/{}/change'.format(
self.event.organizer.slug, self.event.slug, self.order.code
), {
'add-TOTAL_FORMS': '0',
'add-INITIAL_FORMS': '0',
'add-MIN_NUM_FORMS': '0',
'add-MAX_NUM_FORMS': '100',
'other-recalculate_taxes': 'gross',
'op-{}-operation'.format(self.op1.pk): '',
'op-{}-operation'.format(self.op2.pk): '',
'op-{}-itemvar'.format(self.op2.pk): str(self.ticket.pk),
'op-{}-price'.format(self.op2.pk): str(self.op2.price),
'op-{}-itemvar'.format(self.op1.pk): str(self.ticket.pk),
'op-{}-price'.format(self.op1.pk): str(self.op1.price),
})
with scopes_disabled():
ops = list(self.order.positions.all())
for op in ops:
assert op.price == Decimal('23.00')
assert op.tax_value == Decimal('0.00')
assert op.tax_rate == Decimal('0.00')
def test_change_fee_value_success(self):
with scopes_disabled():
fee = self.order.fees.create(fee_type="shipping", value=Decimal('5.00'), tax_rule=self.tr19)

View File

@@ -237,6 +237,18 @@ class CartTest(CartTestMixin, TestCase):
self._set_session('invoice_address', ia.pk)
return ia
def _enable_country_specific_taxing(self):
self.tr19.custom_rules = json.dumps([
{'country': 'EU', 'address_type': 'individual', 'action': 'vat', 'rate': '20.00'},
])
self.tr19.save()
with scopes_disabled():
ia = InvoiceAddress.objects.create(
country=Country('AT'),
)
self._set_session('invoice_address', ia.pk)
return ia
def test_reverse_charge(self):
self._enable_reverse_charge()
response = self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
@@ -251,6 +263,20 @@ class CartTest(CartTestMixin, TestCase):
self.assertEqual(len(objs), 1)
self.assertEqual(objs[0].price, round_decimal(Decimal('23.00') / Decimal('1.19')))
def test_country_specific_taxes(self):
self._enable_country_specific_taxing()
response = self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
'item_%d' % self.ticket.id: '1'
}, follow=True)
self.assertRedirects(response, '/%s/%s/?require_cookie=true' % (self.orga.slug, self.event.slug),
target_status_code=200)
doc = BeautifulSoup(response.rendered_content, "lxml")
self.assertIn('Early-bird', doc.select('.cart .cart-row')[0].select('strong')[0].text)
with scopes_disabled():
objs = list(CartPosition.objects.filter(cart_id=self.session_key, event=self.event))
self.assertEqual(len(objs), 1)
self.assertEqual(objs[0].price, Decimal('23.20'))
def test_subevent_missing(self):
self.event.has_subevents = True
self.event.save()
@@ -3200,6 +3226,182 @@ class CartBundleTest(CartTestMixin, TestCase):
assert a.tax_rate == Decimal('0.00')
assert not a.includes_tax
@classscope(attr='orga')
def test_expired_country_taxing_only_bundled(self):
tr19 = self.event.tax_rules.create(name='VAT', rate=Decimal('19.00'))
ia = InvoiceAddress.objects.create(
country=Country('AT')
)
tr7 = self.event.tax_rules.create(
name='VAT', rate=Decimal('7.00'),
custom_rules=json.dumps([
{'country': 'AT', 'address_type': 'individual', 'action': 'vat', 'rate': '5.00'},
])
)
self.ticket.tax_rule = tr19
self.ticket.save()
self.trans.tax_rule = tr7
self.trans.save()
cp = CartPosition.objects.create(
event=self.event, cart_id=self.session_key, item=self.ticket,
price=21.5, expires=now() - timedelta(minutes=10),
)
a = CartPosition.objects.create(
event=self.event, cart_id=self.session_key, item=self.trans, addon_to=cp,
price=1.47, expires=now() - timedelta(minutes=10), is_bundled=True, override_tax_rate=Decimal('5.00')
)
update_tax_rates(self.event, self.session_key, ia)
cp.refresh_from_db()
a.refresh_from_db()
assert cp.price == Decimal('21.50')
assert cp.tax_rate == Decimal('19.00')
assert cp.includes_tax
assert a.price == Decimal('1.47')
assert a.tax_rate == Decimal('5.00')
assert a.includes_tax
self.cm.invoice_address = ia
self.cm.commit()
cp.refresh_from_db()
a.refresh_from_db()
assert cp.price == Decimal('21.50')
assert cp.tax_rate == Decimal('19.00')
assert cp.includes_tax
assert a.price == Decimal('1.47')
assert a.tax_rate == Decimal('5.00')
assert a.includes_tax
@classscope(attr='orga')
def test_expired_country_tax_all(self):
ia = InvoiceAddress.objects.create(
country=Country('AT')
)
tr19 = self.event.tax_rules.create(
name='VAT', rate=Decimal('19.00'),
custom_rules=json.dumps([
{'country': 'AT', 'address_type': 'individual', 'action': 'vat', 'rate': '20.00'},
])
)
tr7 = self.event.tax_rules.create(
name='VAT', rate=Decimal('7.00'),
custom_rules=json.dumps([
{'country': 'AT', 'address_type': 'individual', 'action': 'vat', 'rate': '5.00'},
])
)
self.ticket.tax_rule = tr19
self.ticket.save()
self.trans.tax_rule = tr7
self.trans.save()
cp = CartPosition.objects.create(
event=self.event, cart_id=self.session_key, item=self.ticket,
price=21.68, expires=now() - timedelta(minutes=10), override_tax_rate=Decimal('20.00')
)
a = CartPosition.objects.create(
event=self.event, cart_id=self.session_key, item=self.trans, addon_to=cp,
price=1.47, expires=now() - timedelta(minutes=10), is_bundled=True, override_tax_rate=Decimal('5.00')
)
update_tax_rates(self.event, self.session_key, ia)
cp.refresh_from_db()
a.refresh_from_db()
assert cp.price == Decimal('21.68')
assert cp.tax_rate == Decimal('20.00')
assert cp.includes_tax
assert a.price == Decimal('1.47')
assert a.tax_rate == Decimal('5.00')
assert a.includes_tax
self.cm.invoice_address = ia
self.cm.commit()
cp.refresh_from_db()
a.refresh_from_db()
assert cp.price == Decimal('21.68')
assert cp.tax_rate == Decimal('20.0')
assert cp.includes_tax
assert a.price == Decimal('1.47')
assert a.tax_rate == Decimal('5.00')
assert a.includes_tax
@classscope(attr='orga')
def test_country_tax_all_add(self):
ia = InvoiceAddress.objects.create(
country=Country('AT')
)
tr19 = self.event.tax_rules.create(
name='VAT', rate=Decimal('19.00'),
custom_rules=json.dumps([
{'country': 'AT', 'address_type': 'individual', 'action': 'vat', 'rate': '20.00'},
])
)
tr7 = self.event.tax_rules.create(
name='VAT', rate=Decimal('7.00'),
custom_rules=json.dumps([
{'country': 'AT', 'address_type': 'individual', 'action': 'vat', 'rate': '5.00'},
])
)
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.68')
assert cp.tax_rate == Decimal('20.00')
assert cp.includes_tax
assert a.price == Decimal('1.47')
assert a.tax_rate == Decimal('5.00')
assert a.includes_tax
@classscope(attr='orga')
def test_country_tax_bundled_add(self):
ia = InvoiceAddress.objects.create(
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'),
custom_rules=json.dumps([
{'country': 'AT', 'address_type': 'individual', 'action': 'vat', 'rate': '5.00'},
])
)
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.47')
assert a.tax_rate == Decimal('5.00')
assert a.includes_tax
class CartSeatingTest(CartTestMixin, TestCase):

View File

@@ -87,6 +87,19 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
self._set_session('invoice_address', ia.pk)
return ia
def _enable_country_specific_taxing(self):
self.tr19.custom_rules = json.dumps([
{'country': 'EU', 'address_type': 'individual', 'action': 'vat', 'rate': '20.00'},
{'country': 'US', 'address_type': 'individual', 'action': 'vat', 'rate': '10.00'},
])
self.tr19.save()
with scopes_disabled():
ia = InvoiceAddress.objects.create(
country=Country('AT'),
)
self._set_session('invoice_address', ia.pk)
return ia
def test_empty_cart(self):
response = self.client.get('/%s/%s/checkout/start' % (self.orga.slug, self.event.slug), follow=True)
self.assertRedirects(response, '/%s/%s/?require_cookie=true' % (self.orga.slug, self.event.slug),
@@ -364,6 +377,50 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
cr1.refresh_from_db()
assert cr1.price == Decimal('23.00')
def test_country_taxing(self):
self._enable_country_specific_taxing()
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': 'individual',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'city': 'Here',
'country': 'AT',
'email': 'admin@localhost'
}, follow=True)
cr1.refresh_from_db()
assert cr1.price == Decimal('23.20')
def test_country_taxing_switch(self):
self.test_country_taxing()
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': 'individual',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'city': 'Here',
'country': 'US',
'state': 'CA',
'email': 'admin@localhost'
}, follow=True)
with scopes_disabled():
cr = CartPosition.objects.get(cart_id=self.session_key)
assert cr.price == Decimal('21.26')
def test_question_file_upload(self):
with scopes_disabled():
q1 = Question.objects.create(