Fix price calculation of included add-ons in expired carts

This commit is contained in:
Raphael Michel
2022-11-18 17:24:02 +01:00
parent 228448b00f
commit f923c2fed0
2 changed files with 24 additions and 2 deletions

View File

@@ -453,12 +453,15 @@ class CartManager:
if cp.is_bundled:
bundle = cp.addon_to.item.bundles.filter(bundled_item=cp.item, bundled_variation=cp.variation).first()
if bundle:
listed_price = bundle.designated_price or 0
listed_price = bundle.designated_price or Decimal('0.00')
else:
listed_price = cp.price
price_after_voucher = listed_price
else:
listed_price = get_listed_price(cp.item, cp.variation, cp.subevent)
if cp.addon_to_id and is_included_for_free(cp.item, cp.addon_to):
listed_price = Decimal('0.00')
else:
listed_price = get_listed_price(cp.item, cp.variation, cp.subevent)
if cp.voucher:
price_after_voucher = cp.voucher.calculate_price(listed_price)
else:

View File

@@ -2380,6 +2380,25 @@ class CartAddonTest(CartTestMixin, TestCase):
assert cp2.item == self.workshop1
assert cp2.price == 0
@classscope(attr='orga')
def test_extend_included_addon(self):
self.addon1.price_included = True
self.addon1.save()
cp1 = CartPosition.objects.create(
expires=now() - timedelta(minutes=10), item=self.ticket, price=Decimal('23.00'),
event=self.event, cart_id=self.session_key
)
cp2 = CartPosition.objects.create(
expires=now() - timedelta(minutes=10), item=self.workshop1, price=Decimal('0.00'),
event=self.event, cart_id=self.session_key, addon_to=cp1
)
self.cm.extend_expired_positions()
self.cm.commit()
cp2.refresh_from_db()
assert cp2.expires > now()
assert cp2.item == self.workshop1
assert cp2.price == 0
@classscope(attr='orga')
def test_cart_addon_remove_parent(self):
self.addon1.price_included = True