Fix #1001 -- Add product bundles (#1041)

* Data model + Editor

* Cart and order management

* Rebase migrations

* Fix typos, add tests on cart handling

* Add tests for checkout and quotas

* Add API endpoints

* Validation of settings

* Front page tax display

* Voucher handling

* Widget foo

* Show correct net pricing

* Front page tests

* reverse charge foo

* Allow to require bundling

* Fix test failure on postgres
This commit is contained in:
Raphael Michel
2019-03-22 14:48:48 +00:00
committed by GitHub
parent c4b18a4c81
commit 90f881c48e
34 changed files with 2747 additions and 153 deletions

View File

@@ -33,6 +33,32 @@ class TaxedPrice:
money_filter(self.gross, currency)
)
def __sub__(self, other):
newgross = self.gross - other.gross
newnet = round_decimal(newgross - (newgross * (1 - 100 / (100 + self.rate)))).quantize(
Decimal('10') ** self.gross.as_tuple().exponent
)
return TaxedPrice(
gross=newgross,
net=newnet,
tax=newgross - newnet,
rate=self.rate,
name=self.name,
)
def __mul__(self, other):
newgross = self.gross * other
newnet = round_decimal(newgross - (newgross * (1 - 100 / (100 + self.rate)))).quantize(
Decimal('10') ** self.gross.as_tuple().exponent
)
return TaxedPrice(
gross=newgross,
net=newnet,
tax=newgross - newnet,
rate=self.rate,
name=self.name,
)
TAXED_ZERO = TaxedPrice(
gross=Decimal('0.00'),
@@ -129,7 +155,12 @@ class TaxRule(LoggedModel):
def has_custom_rules(self):
return self.custom_rules and self.custom_rules != '[]'
def tax(self, base_price, base_price_is='auto'):
def tax(self, base_price, base_price_is='auto', currency=None):
from .event import Event
try:
currency = currency or self.event.currency
except Event.DoesNotExist:
pass
if self.rate == Decimal('0.00'):
return TaxedPrice(
net=base_price, gross=base_price, tax=Decimal('0.00'),
@@ -145,11 +176,11 @@ class TaxRule(LoggedModel):
if base_price_is == 'gross':
gross = base_price
net = round_decimal(gross - (base_price * (1 - 100 / (100 + self.rate))),
self.event.currency if self.event else None)
currency)
elif base_price_is == 'net':
net = base_price
gross = round_decimal((net * (1 + self.rate / 100)),
self.event.currency if self.event else None)
currency)
else:
raise ValueError('Unknown base price type: {}'.format(base_price_is))