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

@@ -11,6 +11,7 @@ from django.utils.functional import cached_property
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from pretix.base.decimal import round_decimal
from pretix.base.i18n import I18nCharField, I18nTextField
from pretix.base.models.base import LoggedModel
@@ -221,6 +222,11 @@ class Item(LoggedModel):
if self.event:
self.event.get_cache().clear()
@property
def default_price_net(self):
tax_value = round_decimal(self.default_price * (1 - 100 / (100 + self.tax_rate)))
return self.default_price - tax_value
def is_available(self, now_dt: datetime=None) -> bool:
"""
Returns whether this item is available according to its ``active`` flag
@@ -313,6 +319,11 @@ class ItemVariation(models.Model):
def price(self):
return self.default_price if self.default_price is not None else self.item.default_price
@property
def net_price(self):
tax_value = round_decimal(self.price * (1 - 100 / (100 + self.item.tax_rate)))
return self.price - tax_value
def delete(self, *args, **kwargs):
super().delete(*args, **kwargs)
if self.item:

View File

@@ -7,10 +7,11 @@ from typing import List, Union
from django.conf import settings
from django.db import models
from django.db.models import F
from django.db.models import F, Sum
from django.db.models.signals import post_delete
from django.dispatch import receiver
from django.utils.crypto import get_random_string
from django.utils.functional import cached_property
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
@@ -215,6 +216,18 @@ class Order(LoggedModel):
else:
self.payment_fee_tax_value = Decimal('0.00')
@property
def payment_fee_net(self):
return self.payment_fee - self.payment_fee_tax_value
@cached_property
def tax_total(self):
return (self.positions.aggregate(s=Sum('tax_value'))['s'] or 0) + self.payment_fee_tax_value
@property
def net_total(self):
return self.total - self.tax_total
@staticmethod
def normalize_code(code):
tr = str.maketrans({
@@ -432,6 +445,10 @@ class AbstractPosition(models.Model):
else:
q.answer = ""
@property
def net_price(self):
return self.price - self.tax_value
class OrderPosition(AbstractPosition):
"""

View File

@@ -9,6 +9,7 @@ from django.db.models import Q
from django.utils.timezone import now
from django.utils.translation import ugettext as _
from pretix.base.decimal import round_decimal
from pretix.base.i18n import LazyLocaleException
from pretix.base.models import (
CartPosition, Event, Item, ItemVariation, Voucher,
@@ -143,6 +144,8 @@ class CartManager:
custom_price = Decimal(custom_price.replace(",", "."))
if custom_price > 100000000:
return error_messages['price_too_high']
if self.event.settings.display_net_prices:
custom_price = round_decimal(custom_price * (100 + item.tax_rate) / 100)
price = max(custom_price, price)
return price

View File

@@ -20,6 +20,10 @@ DEFAULTS = {
'default': '10',
'type': int
},
'display_net_prices': {
'default': 'False',
'type': bool
},
'attendee_names_asked': {
'default': 'True',
'type': bool