Ver código fonte

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 anos atrás
pai
commit
3f7101a529
Nenhuma conta vinculada ao e-mail do autor do commit

+ 1
- 1
src/oscar/apps/basket/utils.py Ver arquivo

@@ -163,7 +163,7 @@ class LineOfferConsumer(object):
163 163
                     if a.exclusive:
164 164
                         if any([
165 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 168
                             # Exclusive offers cannot be applied if any other exclusive
169 169
                             # offer with higher priority is active already.

+ 30
- 1
tests/integration/basket/test_utils.py Ver arquivo

@@ -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')

Carregando…
Cancelar
Salvar