|
|
@@ -4,7 +4,7 @@ import pytest
|
|
4
|
4
|
from oscar.apps.offer import models
|
|
5
|
5
|
from oscar.apps.offer.applicator import Applicator
|
|
6
|
6
|
from oscar.test.factories import (
|
|
7
|
|
- BasketFactory, ConditionalOfferFactory, ProductFactory)
|
|
|
7
|
+ BasketFactory, ConditionalOfferFactory, ProductFactory, VoucherFactory)
|
|
8
|
8
|
|
|
9
|
9
|
|
|
10
|
10
|
@pytest.fixture
|
|
|
@@ -220,6 +220,35 @@ class TestLineOfferConsumer:
|
|
220
|
220
|
assert len(basket.offer_applications.offer_discounts) == 1
|
|
221
|
221
|
assert [x.consumer.consumed() for x in basket.all_lines()] == [1, 0]
|
|
222
|
222
|
|
|
|
223
|
+ def test_apply_multiple_vouchers(self, filled_basket):
|
|
|
224
|
+ offer1 = ConditionalOfferFactory(
|
|
|
225
|
+ condition__range__includes_all_products=True,
|
|
|
226
|
+ benefit__range__includes_all_products=True,
|
|
|
227
|
+ name='offer1',
|
|
|
228
|
+ exclusive=True,
|
|
|
229
|
+ )
|
|
|
230
|
+ voucher1 = VoucherFactory(name="voucher1", code="VOUCHER1")
|
|
|
231
|
+ voucher1.offers.add(offer1)
|
|
|
232
|
+ offer2 = ConditionalOfferFactory(
|
|
|
233
|
+ condition__range__includes_all_products=True,
|
|
|
234
|
+ benefit__range__includes_all_products=True,
|
|
|
235
|
+ name='offer2',
|
|
|
236
|
+ exclusive=True,
|
|
|
237
|
+ )
|
|
|
238
|
+ voucher2 = VoucherFactory(name="voucher2", code="VOUCHER2")
|
|
|
239
|
+ voucher2.offers.add(offer2)
|
|
|
240
|
+ offer1.exclusive = True
|
|
|
241
|
+ offer2.exclusive = True
|
|
|
242
|
+
|
|
|
243
|
+ assert len(filled_basket.offer_applications) == 0
|
|
|
244
|
+ Applicator().apply_offers(
|
|
|
245
|
+ basket=filled_basket,
|
|
|
246
|
+ offers=[offer2, offer1]
|
|
|
247
|
+ )
|
|
|
248
|
+ filled_basket.refresh_from_db()
|
|
|
249
|
+ # Only one should be applied because they're both exclusive.
|
|
|
250
|
+ assert len(filled_basket.offer_applications) == 1
|
|
|
251
|
+
|
|
223
|
252
|
def test_consumed_with_combined_offer(self, filled_basket):
|
|
224
|
253
|
offer1 = ConditionalOfferFactory(name='offer1')
|
|
225
|
254
|
offer2 = ConditionalOfferFactory(name='offer2')
|