forked from CGM_Public/pretix_original
Introduce a setting to show net prices (#415)
* Introduce a setting to show net prices in the frontend * Show net prices in the backend as well
This commit is contained in:
@@ -6,6 +6,7 @@ from django.db.models import Sum
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.timezone import now
|
||||
|
||||
from pretix.base.decimal import round_decimal
|
||||
from pretix.base.models import CartPosition, OrderPosition
|
||||
from pretix.base.signals import register_payment_providers
|
||||
|
||||
@@ -44,10 +45,10 @@ class CartMixin:
|
||||
else:
|
||||
i = pos.pk
|
||||
if downloads:
|
||||
return i, pos.pk, 0, 0, 0, 0
|
||||
return i, pos.pk, 0, 0, 0, 0,
|
||||
if answers and ((pos.item.admission and self.request.event.settings.attendee_names_asked)
|
||||
or pos.item.questions.all()):
|
||||
return i, pos.pk, 0, 0, 0, 0
|
||||
return i, pos.pk, 0, 0, 0, 0,
|
||||
return 0, 0, pos.item_id, pos.variation_id, pos.price, (pos.voucher_id or 0)
|
||||
|
||||
positions = []
|
||||
@@ -56,15 +57,24 @@ class CartMixin:
|
||||
group = g[0]
|
||||
group.count = len(g)
|
||||
group.total = group.count * group.price
|
||||
group.net_total = group.count * group.net_price
|
||||
group.has_questions = answers and k[0] != ""
|
||||
if answers:
|
||||
group.cache_answers()
|
||||
positions.append(group)
|
||||
|
||||
total = sum(p.total for p in positions)
|
||||
net_total = sum(p.net_total for p in positions)
|
||||
tax_total = sum(p.total - p.net_total for p in positions)
|
||||
|
||||
payment_fee = payment_fee if payment_fee is not None else self.get_payment_fee(total)
|
||||
payment_fee_tax_rate = payment_fee_tax_rate if payment_fee_tax_rate is not None else self.request.event.settings.tax_rate_default
|
||||
payment_fee_tax_rate = round_decimal(payment_fee_tax_rate
|
||||
if payment_fee_tax_rate is not None
|
||||
else self.request.event.settings.tax_rate_default)
|
||||
payment_fee_tax_value = round_decimal(payment_fee * (1 - 100 / (100 + payment_fee_tax_rate)))
|
||||
payment_fee_net = payment_fee - payment_fee_tax_value
|
||||
tax_total += payment_fee_tax_value
|
||||
net_total += payment_fee_net
|
||||
|
||||
try:
|
||||
first_expiry = min(p.expires for p in positions) if positions else now()
|
||||
@@ -77,7 +87,10 @@ class CartMixin:
|
||||
'positions': positions,
|
||||
'raw': cartpos,
|
||||
'total': total + payment_fee,
|
||||
'net_total': net_total,
|
||||
'tax_total': tax_total,
|
||||
'payment_fee': payment_fee,
|
||||
'payment_fee_net': payment_fee_net,
|
||||
'payment_fee_tax_rate': payment_fee_tax_rate,
|
||||
'answers': answers,
|
||||
'minutes_left': minutes_left,
|
||||
|
||||
@@ -6,6 +6,7 @@ from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import TemplateView, View
|
||||
|
||||
from pretix.base.decimal import round_decimal
|
||||
from pretix.base.models import CartPosition, Quota, Voucher
|
||||
from pretix.base.services.cart import (
|
||||
CartError, add_items_to_cart, remove_items_from_cart,
|
||||
@@ -189,6 +190,8 @@ class RedeemView(EventViewMixin, TemplateView):
|
||||
else:
|
||||
item.cached_availability = item.check_quotas()
|
||||
item.price = self.voucher.calculate_price(item.default_price)
|
||||
if self.request.event.settings.display_net_prices:
|
||||
item.price -= round_decimal(item.price * (1 - 100 / (100 + item.tax_rate)))
|
||||
else:
|
||||
for var in item.available_variations:
|
||||
if self.voucher.allow_ignore_quota or self.voucher.block_quota:
|
||||
@@ -196,10 +199,12 @@ class RedeemView(EventViewMixin, TemplateView):
|
||||
else:
|
||||
var.cached_availability = list(var.check_quotas())
|
||||
var.display_price = self.voucher.calculate_price(var.price)
|
||||
if self.request.event.settings.display_net_prices:
|
||||
var.display_price -= round_decimal(var.display_price * (1 - 100 / (100 + item.tax_rate)))
|
||||
|
||||
if len(item.available_variations) > 0:
|
||||
item.min_price = min([v.price for v in item.available_variations])
|
||||
item.max_price = max([v.price for v in item.available_variations])
|
||||
item.min_price = min([v.display_price for v in item.available_variations])
|
||||
item.max_price = max([v.display_price for v in item.available_variations])
|
||||
|
||||
items = [item for item in items if len(item.available_variations) > 0 or not item.has_variations]
|
||||
context['options'] = sum([(len(item.available_variations) if item.has_variations else 1)
|
||||
|
||||
@@ -63,6 +63,7 @@ def get_grouped_items(event):
|
||||
if item.cached_availability[1] is not None else sys.maxsize,
|
||||
int(event.settings.max_items_per_order))
|
||||
item.price = item.default_price
|
||||
item.display_price = item.default_price_net if event.settings.display_net_prices else item.price
|
||||
display_add_to_cart = display_add_to_cart or item.order_max > 0
|
||||
else:
|
||||
for var in item.available_variations:
|
||||
@@ -70,10 +71,11 @@ def get_grouped_items(event):
|
||||
var.order_max = min(var.cached_availability[1]
|
||||
if var.cached_availability[1] is not None else sys.maxsize,
|
||||
int(event.settings.max_items_per_order))
|
||||
var.display_price = var.net_price if event.settings.display_net_prices else var.price
|
||||
display_add_to_cart = display_add_to_cart or var.order_max > 0
|
||||
if len(item.available_variations) > 0:
|
||||
item.min_price = min([v.price for v in item.available_variations])
|
||||
item.max_price = max([v.price for v in item.available_variations])
|
||||
item.min_price = min([v.display_price for v in item.available_variations])
|
||||
item.max_price = max([v.display_price for v in item.available_variations])
|
||||
|
||||
items = [item for item in items if len(item.available_variations) > 0 or not item.has_variations]
|
||||
return items, display_add_to_cart
|
||||
|
||||
Reference in New Issue
Block a user