mirror of
https://github.com/pretix/pretix-servicefees.git
synced 2025-04-30 10:12:35 +02:00
Use new tax default and split function
This commit is contained in:
parent
6c52b0d5d1
commit
7d0373fde8
2 changed files with 4 additions and 40 deletions
pretix_servicefees
|
@ -8,6 +8,7 @@ from django.utils.translation import gettext, gettext_lazy as _
|
||||||
from pretix.base.decimal import round_decimal
|
from pretix.base.decimal import round_decimal
|
||||||
from pretix.base.models import CartPosition, Event, TaxRule
|
from pretix.base.models import CartPosition, Event, TaxRule
|
||||||
from pretix.base.models.orders import OrderFee
|
from pretix.base.models.orders import OrderFee
|
||||||
|
from pretix.base.services.tax import split_fee_for_taxes
|
||||||
from pretix.base.settings import settings_hierarkey
|
from pretix.base.settings import settings_hierarkey
|
||||||
from pretix.base.signals import (
|
from pretix.base.signals import (
|
||||||
event_copy_data,
|
event_copy_data,
|
||||||
|
@ -139,46 +140,9 @@ def get_fees(
|
||||||
)
|
)
|
||||||
split_taxes = event.settings.get("service_fee_split_taxes", as_type=bool)
|
split_taxes = event.settings.get("service_fee_split_taxes", as_type=bool)
|
||||||
if split_taxes:
|
if split_taxes:
|
||||||
# split taxes based on products ordered
|
fee_values = split_fee_for_taxes(positions, fee, event)
|
||||||
d = defaultdict(lambda: Decimal("0.00"))
|
|
||||||
trs = {}
|
|
||||||
for p in positions:
|
|
||||||
if isinstance(p, CartPosition):
|
|
||||||
tr = p.item.tax_rule
|
|
||||||
else:
|
|
||||||
tr = p.tax_rule
|
|
||||||
if not tr:
|
|
||||||
tr = tax_rule_zero
|
|
||||||
# use tr.pk as key as tax_rule_zero is not hashable
|
|
||||||
d[tr.pk] += p.price - p.tax_value
|
|
||||||
trs[tr.pk] = tr
|
|
||||||
|
|
||||||
base_values = sorted([(trs[key], value) for key, value in d.items()], key=lambda t: t[0].rate)
|
|
||||||
sum_base = sum(value for key, value in base_values)
|
|
||||||
if sum_base:
|
|
||||||
fee_values = [
|
|
||||||
(key, round_decimal(fee * value / sum_base, event.currency))
|
|
||||||
for key, value in base_values
|
|
||||||
]
|
|
||||||
sum_fee = sum(value for key, value in fee_values)
|
|
||||||
|
|
||||||
# If there are rounding differences, we fix them up, but always leaning to the benefit of the tax
|
|
||||||
# authorities
|
|
||||||
if sum_fee > fee:
|
|
||||||
fee_values[0] = (
|
|
||||||
fee_values[0][0],
|
|
||||||
fee_values[0][1] + (fee - sum_fee),
|
|
||||||
)
|
|
||||||
elif sum_fee < fee:
|
|
||||||
fee_values[-1] = (
|
|
||||||
fee_values[-1][0],
|
|
||||||
fee_values[-1][1] + (fee - sum_fee),
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
fee_values = [(event.settings.tax_rate_default or tax_rule_zero, fee)]
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
fee_values = [(event.settings.tax_rate_default or tax_rule_zero, fee)]
|
fee_values = [(event.settings.cached_default_tax_rule or tax_rule_zero, fee)]
|
||||||
|
|
||||||
fees = []
|
fees = []
|
||||||
for tax_rule, price in fee_values:
|
for tax_rule, price in fee_values:
|
||||||
|
|
|
@ -57,7 +57,7 @@ class ServiceFeeSettingsForm(SettingsForm):
|
||||||
"Split taxes proportionate to the tax rates and net values of the ordered products."
|
"Split taxes proportionate to the tax rates and net values of the ordered products."
|
||||||
),
|
),
|
||||||
help_text=_(
|
help_text=_(
|
||||||
"If not split based on ordered products, the tax rate falls back to the event’s base tax rate or no tax, if none is given."
|
"If not split based on ordered products, the tax rate falls back to the event’s default tax rate or no tax, if no default tax rate exists."
|
||||||
),
|
),
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue