Skip to content

Commit

Permalink
Discounts: Fix scoping error with distinct subevents
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Nov 29, 2023
1 parent 66f934b commit b92feb3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/pretix/base/models/discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,10 @@ def key(idx):
break

for g in candidate_groups:
self._apply_min_count(positions, g, g, result)
self._apply_min_count(
positions,
[idx for idx in g if idx in condition_candidates],
[idx for idx in g if idx in benefit_candidates],
result
)
return result
25 changes: 25 additions & 0 deletions src/tests/base/test_pricing_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,31 @@ def test_limit_products(event, item, item2):
assert sorted(new_prices) == sorted(expected)


@pytest.mark.django_db
@scopes_disabled()
def test_limit_products_subevents_distinct(event, item, item2):
d1 = Discount(event=event, condition_min_count=2, benefit_discount_matching_percent=20, condition_all_products=False,
subevent_mode=Discount.SUBEVENT_MODE_DISTINCT)
d1.save()
d1.condition_limit_products.add(item)

positions = (
(item.pk, 1, Decimal('100.00'), False, False, Decimal('0.00')),
(item.pk, 2, Decimal('100.00'), False, False, Decimal('0.00')),
(item.pk, 3, Decimal('100.00'), False, False, Decimal('0.00')),
(item2.pk, 4, Decimal('50.00'), False, False, Decimal('0.00')),
)
expected = (
Decimal('80.00'),
Decimal('80.00'),
Decimal('80.00'),
Decimal('50.00'),
)

new_prices = [p for p, d in apply_discounts(event, 'web', positions)]
assert sorted(new_prices) == sorted(expected)


@pytest.mark.django_db
@scopes_disabled()
def test_sales_channels(event, item):
Expand Down

0 comments on commit b92feb3

Please sign in to comment.