forked from CGM_Public/pretix_original
Fix tax calculation issue
This commit is contained in:
@@ -1874,7 +1874,7 @@ class OrderFee(models.Model):
|
||||
self.tax_rule = self.order.event.settings.tax_rate_default
|
||||
|
||||
if self.tax_rule:
|
||||
tax = self.tax_rule.tax(self.value, base_price_is='gross', invoice_address=ia)
|
||||
tax = self.tax_rule.tax(self.value, base_price_is='gross', invoice_address=ia, force_fixed_gross_price=True)
|
||||
self.tax_rate = tax.rate
|
||||
self.tax_value = tax.tax
|
||||
else:
|
||||
@@ -2026,7 +2026,7 @@ class OrderPosition(AbstractPosition):
|
||||
except InvoiceAddress.DoesNotExist:
|
||||
ia = None
|
||||
if self.tax_rule:
|
||||
tax = self.tax_rule.tax(self.price, invoice_address=ia, base_price_is='gross')
|
||||
tax = self.tax_rule.tax(self.price, invoice_address=ia, base_price_is='gross', force_fixed_gross_price=True)
|
||||
self.tax_rate = tax.rate
|
||||
self.tax_value = tax.tax
|
||||
else:
|
||||
|
||||
@@ -188,7 +188,7 @@ class TaxRule(LoggedModel):
|
||||
return Decimal(self.rate)
|
||||
|
||||
def tax(self, base_price, base_price_is='auto', currency=None, override_tax_rate=None, invoice_address=None,
|
||||
subtract_from_gross=Decimal('0.00'), gross_price_is_tax_rate: Decimal = None):
|
||||
subtract_from_gross=Decimal('0.00'), gross_price_is_tax_rate: Decimal = None, force_fixed_gross_price=False):
|
||||
from .event import Event
|
||||
try:
|
||||
currency = currency or self.event.currency
|
||||
@@ -200,7 +200,7 @@ class TaxRule(LoggedModel):
|
||||
rate = override_tax_rate
|
||||
elif invoice_address:
|
||||
adjust_rate = self.tax_rate_for(invoice_address)
|
||||
if adjust_rate == gross_price_is_tax_rate and base_price_is == 'gross':
|
||||
if (adjust_rate == gross_price_is_tax_rate or force_fixed_gross_price) and base_price_is == 'gross':
|
||||
rate = adjust_rate
|
||||
elif adjust_rate != rate:
|
||||
normal_price = self.tax(base_price, base_price_is, currency, subtract_from_gross=subtract_from_gross)
|
||||
|
||||
@@ -2512,7 +2512,7 @@ class OrderChangeManagerTests(TestCase):
|
||||
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')
|
||||
assert nop.tax_value == Decimal('11.50')
|
||||
|
||||
@classscope(attr='o')
|
||||
def test_change_taxrate_from_reverse_charge(self):
|
||||
|
||||
@@ -427,7 +427,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
|
||||
cr1.refresh_from_db()
|
||||
assert cr1.price == Decimal('19.33')
|
||||
|
||||
def test_country_taxing(self):
|
||||
def _test_country_taxing(self):
|
||||
self._enable_country_specific_taxing()
|
||||
|
||||
with scopes_disabled():
|
||||
@@ -450,6 +450,25 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
|
||||
|
||||
cr1.refresh_from_db()
|
||||
assert cr1.price == Decimal('23.20')
|
||||
assert cr1.override_tax_rate == Decimal('20.00')
|
||||
assert cr1.tax_value == Decimal('3.87')
|
||||
return cr1
|
||||
|
||||
def test_country_taxing(self):
|
||||
cr1 = self._test_country_taxing()
|
||||
|
||||
self.client.post('/%s/%s/checkout/payment/' % (self.orga.slug, self.event.slug), {
|
||||
'payment': 'banktransfer'
|
||||
}, follow=True)
|
||||
|
||||
self.client.post('/%s/%s/checkout/confirm/' % (self.orga.slug, self.event.slug), follow=True)
|
||||
with scopes_disabled():
|
||||
assert not CartPosition.objects.filter(pk=cr1.pk).exists()
|
||||
o = Order.objects.last()
|
||||
pos = o.positions.get()
|
||||
assert pos.price == Decimal('23.20')
|
||||
assert pos.tax_rate == Decimal('20.00')
|
||||
assert pos.tax_value == Decimal('3.87')
|
||||
|
||||
def test_country_taxing_free_price_and_voucher(self):
|
||||
self._enable_country_specific_taxing()
|
||||
@@ -490,7 +509,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
|
||||
assert o.positions.get().price == Decimal('23.20')
|
||||
|
||||
def test_country_taxing_switch(self):
|
||||
self.test_country_taxing()
|
||||
self._test_country_taxing()
|
||||
|
||||
with mock.patch('vat_moss.id.validate') as mock_validate:
|
||||
mock_validate.return_value = ('AT', 'AT123456', 'Foo')
|
||||
|
||||
Reference in New Issue
Block a user