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:
Raphael Michel
2017-02-22 16:59:54 +01:00
committed by GitHub
parent 08e7a29623
commit ed04f3124f
16 changed files with 206 additions and 43 deletions

View File

@@ -70,22 +70,35 @@
<input type="hidden" name="item_{{ line.item.id }}"
value="1" />
<input type="hidden" name="price_{{ line.item.id }}"
value="{{ line.price }}" />
value="{% if event.settings.display_net_prices %}{{ line.net_price }}{% else %}{{ line.price }}{% endif %}" />
{% endif %}
<button class="btn btn-mini btn-link"><i class="fa fa-plus"></i></button>
</form>
{% endif %}
</div>
<div class="singleprice price">
{{ event.currency }} {{ line.price|floatformat:2 }}
{% if event.settings.display_net_prices %}
{{ event.currency }} {{ line.net_price|floatformat:2 }}
{% else %}
{{ event.currency }} {{ line.price|floatformat:2 }}
{% endif %}
</div>
{% endif %}
<div class="totalprice price">
<strong>{{ event.currency }} {{ line.total|floatformat:2 }}</strong>
{% if line.tax_rate %}
<br /><small>{% blocktrans trimmed with rate=line.tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>
{% if event.settings.display_net_prices %}
<strong>{{ event.currency }} {{ line.net_total|floatformat:2 }}</strong>
{% if line.tax_rate %}
<br /><small>{% blocktrans trimmed with rate=line.tax_rate %}
<strong>plus</strong> {{ rate }}% taxes
{% endblocktrans %}</small>
{% endif %}
{% else %}
<strong>{{ event.currency }} {{ line.total|floatformat:2 }}</strong>
{% if line.tax_rate %}
<br /><small>{% blocktrans trimmed with rate=line.tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>
{% endif %}
{% endif %}
</div>
{% if download %}
@@ -102,23 +115,52 @@
</div>
{% endfor %}
{% if cart.payment_fee %}
{# TODO: Tax rate? #}
<div class="row cart-row">
<div class="col-md-4 col-xs-6">
<strong>{% trans "Payment method fee" %}</strong>
</div>
<div class="col-md-3 col-xs-6 col-md-offset-5 price">
<strong>{{ event.currency }} {{ cart.payment_fee|floatformat:2 }}</strong>
{% if cart.payment_fee_tax_rate %}
<br/>
<small>{% blocktrans trimmed with rate=cart.payment_fee_tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>
{% if event.settings.display_net_prices %}
<strong>{{ event.currency }} {{ cart.payment_fee_net|floatformat:2 }}</strong>
{% if cart.payment_fee_tax_rate %}
<br/>
<small>{% blocktrans trimmed with rate=cart.payment_fee_tax_rate %}
<strong>plus</strong> {{ rate }}% taxes
{% endblocktrans %}</small>
{% endif %}
{% else %}
<strong>{{ event.currency }} {{ cart.payment_fee|floatformat:2 }}</strong>
{% if cart.payment_fee_tax_rate %}
<br/>
<small>{% blocktrans trimmed with rate=cart.payment_fee_tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>
{% endif %}
{% endif %}
</div>
<div class="clearfix"></div>
</div>
{% endif %}
{% if event.settings.display_net_prices %}
<div class="row cart-row total">
<div class="col-md-4 col-xs-6">
<strong>{% trans "Net total" %}</strong>
</div>
<div class="col-md-3 col-xs-6 col-md-offset-5 price">
{{ event.currency }} {{ cart.net_total|floatformat:2 }}
</div>
<div class="clearfix"></div>
</div>
<div class="row cart-row">
<div class="col-md-4 col-xs-6">
<strong>{% trans "Taxes" %}</strong>
</div>
<div class="col-md-3 col-xs-6 col-md-offset-5 price">
{{ event.currency }} {{ cart.tax_total|floatformat:2 }}
</div>
<div class="clearfix"></div>
</div>
{% endif %}
<div class="row cart-row total">
<div class="col-md-4 col-xs-6">
<strong>{% trans "Total" %}</strong>

View File

@@ -136,14 +136,18 @@
<span class="input-group-addon">{{ event.currency }}</span>
<input type="number" class="form-control input-item-price"
placeholder="0"
min="{{ var.price|stringformat:"0.2f" }}"
min="{{ var.display_price|stringformat:"0.2f" }}"
name="price_{{ item.id }}_{{ var.id }}"
step="any" value="{{ var.price|stringformat:"0.2f" }}">
step="any" value="{{ var.display_price|stringformat:"0.2f" }}">
</div>
{% else %}
{{ event.currency }} {{ var.price|floatformat:2 }}
{{ event.currency }} {{ var.display_price|floatformat:2 }}
{% endif %}
{% if item.tax_rate %}
{% if item.tax_rate and event.settings.display_net_prices %}
<small>{% blocktrans trimmed with rate=item.tax_rate %}
<strong>plus</strong> {{ rate }}% taxes
{% endblocktrans %}</small>
{% elif item.tax_rate %}
<small>{% blocktrans trimmed with rate=item.tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>
@@ -186,14 +190,18 @@
<div class="input-group input-group-price">
<span class="input-group-addon">{{ event.currency }}</span>
<input type="number" class="form-control input-item-price" placeholder="0"
min="{{ item.price|stringformat:"0.2f" }}"
min="{{ item.display_price|stringformat:"0.2f" }}"
name="price_{{ item.id }}"
step="any" value="{{ item.price|stringformat:"0.2f" }}">
step="any" value="{{ item.display_price|stringformat:"0.2f" }}">
</div>
{% else %}
{{ event.currency }} {{ item.price|floatformat:2 }}
{{ event.currency }} {{ item.display_price|floatformat:2 }}
{% endif %}
{% if item.tax_rate %}
{% if item.tax_rate and event.settings.display_net_prices %}
<small>{% blocktrans trimmed with rate=item.tax_rate %}
<strong>plus</strong> {{ rate }}% taxes
{% endblocktrans %}</small>
{% elif item.tax_rate %}
<small>{% blocktrans trimmed with rate=item.tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>

View File

@@ -72,7 +72,11 @@
{% else %}
{{ event.currency }} {{ var.display_price|floatformat:2 }}
{% endif %}
{% if item.tax_rate %}
{% if item.tax_rate and event.settings.display_net_prices %}
<small>{% blocktrans trimmed with rate=item.tax_rate %}
<strong>plus</strong> {{ rate }}% taxes
{% endblocktrans %}</small>
{% elif item.tax_rate %}
<small>{% blocktrans trimmed with rate=item.tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>
@@ -126,7 +130,11 @@
{% else %}
{{ event.currency }} {{ item.price|floatformat:2 }}
{% endif %}
{% if item.tax_rate %}
{% if item.tax_rate and event.settings.display_net_prices %}
<small>{% blocktrans trimmed with rate=item.tax_rate %}
<strong>plus</strong> {{ rate }}% taxes
{% endblocktrans %}</small>
{% elif item.tax_rate %}
<small>{% blocktrans trimmed with rate=item.tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>

View File

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

View File

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

View File

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