Bundle behaviour

This commit is contained in:
Raphael Michel
2019-12-11 13:31:56 +01:00
parent 8822d572f5
commit dc298c4202
2 changed files with 53 additions and 1 deletions

View File

@@ -450,7 +450,17 @@ class CartManager:
if voucher.subevent_id and voucher.subevent_id != p.subevent_id: if voucher.subevent_id and voucher.subevent_id != p.subevent_id:
continue continue
price = self._get_price(p.item, p.variation, voucher, None, p.subevent) if p.is_bundled:
continue
bundled_sum = Decimal('0.00')
if not p.addon_to_id:
for bundledp in p.addons.all():
if bundledp.is_bundled:
bundledprice = bundledp.price
bundled_sum += bundledprice
price = self._get_price(p.item, p.variation, voucher, None, p.subevent, bundled_sum=bundled_sum)
if price.gross > p.price: if price.gross > p.price:
continue continue

View File

@@ -2857,6 +2857,48 @@ class CartBundleTest(CartTestMixin, TestCase):
assert cp.price == 0 assert cp.price == 0
assert b.price == 40 assert b.price == 40
@classscope(attr='orga')
def test_voucher_apply_multiple(self):
cp = CartPosition.objects.create(
event=self.event, cart_id=self.session_key, item=self.ticket,
price=21.5, expires=now() + timedelta(minutes=10)
)
b = CartPosition.objects.create(
event=self.event, cart_id=self.session_key, item=self.trans, addon_to=cp,
price=1.5, expires=now() + timedelta(minutes=10), is_bundled=True
)
v = Voucher.objects.create(
event=self.event, price_mode='set', value=Decimal('4.00'), max_usages=100
)
self.cm.apply_voucher(v.code)
self.cm.commit()
cp.refresh_from_db()
b.refresh_from_db()
assert cp.price == Decimal('2.50')
assert b.price == Decimal('1.50')
@classscope(attr='orga')
def test_voucher_apply_multiple_reduce_beyond_designated_price(self):
cp = CartPosition.objects.create(
event=self.event, cart_id=self.session_key, item=self.ticket,
price=21.5, expires=now() + timedelta(minutes=10)
)
b = CartPosition.objects.create(
event=self.event, cart_id=self.session_key, item=self.trans, addon_to=cp,
price=1.5, expires=now() + timedelta(minutes=10), is_bundled=True
)
v = Voucher.objects.create(
event=self.event, price_mode='set', value=Decimal('0.00'), max_usages=100
)
self.cm.apply_voucher(v.code)
self.cm.commit()
cp.refresh_from_db()
b.refresh_from_db()
assert cp.price == Decimal('0.00')
assert b.price == Decimal('1.50')
@classscope(attr='orga') @classscope(attr='orga')
def test_extend_base_price_changed(self): def test_extend_base_price_changed(self):
cp = CartPosition.objects.create( cp = CartPosition.objects.create(