Browse Source

Exclusivevoucherbug (#4095)

* fix that a exclusive voucher is really exclusive

* add test

* consume offer 2 instead of 1

* fix that a exclusive voucher is really exclusive

* add test

* consume offer 2 instead of 1

* test 2.0

* Add proper test for multiple vouchers

---------

Co-authored-by: wessel <wessel@highbiza.nl>
master
Joey 2 years ago
parent
commit
3f7101a529
No account linked to committer's email address
2 changed files with 31 additions and 2 deletions
  1. 1
    1
      src/oscar/apps/basket/utils.py
  2. 30
    1
      tests/integration/basket/test_utils.py

+ 1
- 1
src/oscar/apps/basket/utils.py View File

163
                     if a.exclusive:
163
                     if a.exclusive:
164
                         if any([
164
                         if any([
165
                             a.priority > offer.priority,
165
                             a.priority > offer.priority,
166
-                            a.priority == offer.priority and a.id < offer.id
166
+                            a.priority == offer.priority and a.id != offer.id
167
                         ]):
167
                         ]):
168
                             # Exclusive offers cannot be applied if any other exclusive
168
                             # Exclusive offers cannot be applied if any other exclusive
169
                             # offer with higher priority is active already.
169
                             # offer with higher priority is active already.

+ 30
- 1
tests/integration/basket/test_utils.py View File

4
 from oscar.apps.offer import models
4
 from oscar.apps.offer import models
5
 from oscar.apps.offer.applicator import Applicator
5
 from oscar.apps.offer.applicator import Applicator
6
 from oscar.test.factories import (
6
 from oscar.test.factories import (
7
-    BasketFactory, ConditionalOfferFactory, ProductFactory)
7
+    BasketFactory, ConditionalOfferFactory, ProductFactory, VoucherFactory)
8
 
8
 
9
 
9
 
10
 @pytest.fixture
10
 @pytest.fixture
220
         assert len(basket.offer_applications.offer_discounts) == 1
220
         assert len(basket.offer_applications.offer_discounts) == 1
221
         assert [x.consumer.consumed() for x in basket.all_lines()] == [1, 0]
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
     def test_consumed_with_combined_offer(self, filled_basket):
252
     def test_consumed_with_combined_offer(self, filled_basket):
224
         offer1 = ConditionalOfferFactory(name='offer1')
253
         offer1 = ConditionalOfferFactory(name='offer1')
225
         offer2 = ConditionalOfferFactory(name='offer2')
254
         offer2 = ConditionalOfferFactory(name='offer2')

Loading…
Cancel
Save