Просмотр исходного кода

Merge pull request #1922 from edoburu/fix/weightbased-discount

Fix errors with shipping discounts on free weightbased shipping.
master
Maik Hoepfel 9 лет назад
Родитель
Сommit
85e5f410d3

+ 7
- 5
src/oscar/apps/shipping/abstract_models.py Просмотреть файл

@@ -39,6 +39,13 @@ class AbstractBase(models.Model):
39 39
     def __str__(self):
40 40
         return self.name
41 41
 
42
+    def discount(self, basket):
43
+        """
44
+        Return the discount on the standard shipping charge
45
+        """
46
+        # This method is identical to the Base.discount().
47
+        return D('0.00')
48
+
42 49
 
43 50
 class AbstractOrderAndItemCharges(AbstractBase):
44 51
     """
@@ -95,7 +102,6 @@ class AbstractWeightBased(AbstractBase):
95 102
 
96 103
     code = 'weight-based-shipping'
97 104
     name = _('Weight-based shipping')
98
-    offer = None
99 105
 
100 106
     # The default weight to use (in kg) when a product doesn't have a weight
101 107
     # attribute.
@@ -179,10 +185,6 @@ class AbstractWeightBased(AbstractBase):
179 185
         except IndexError:
180 186
             return None
181 187
 
182
-    def discount(self, basket):
183
-        base_charge = self.calculate(basket)
184
-        return self.offer.shipping_discount(base_charge.incl_tax)
185
-
186 188
 
187 189
 @python_2_unicode_compatible
188 190
 class AbstractWeightBand(models.Model):

+ 3
- 0
src/oscar/apps/shipping/methods.py Просмотреть файл

@@ -40,6 +40,9 @@ class Base(object):
40 40
         """
41 41
         Return the discount on the standard shipping charge
42 42
         """
43
+        # The regular shipping methods don't add a default discount.
44
+        # For offers and vouchers, the discount will be provided
45
+        # by a wrapper that Repository.apply_shipping_offer() adds.
43 46
         return D('0.00')
44 47
 
45 48
 

+ 24
- 0
tests/integration/shipping/model_method_tests.py Просмотреть файл

@@ -2,7 +2,10 @@ from decimal import Decimal as D
2 2
 
3 3
 from django.test import TestCase
4 4
 
5
+from oscar.apps.offer.applicator import Applicator
6
+from oscar.apps.offer.models import Benefit
5 7
 from oscar.apps.shipping.models import OrderAndItemCharges, WeightBased
8
+from oscar.apps.shipping.repository import Repository
6 9
 from oscar.core.compat import get_user_model
7 10
 from oscar.test import factories
8 11
 
@@ -198,3 +201,24 @@ class WeightBasedMethodTests(TestCase):
198 201
         charge = self.standard.calculate(basket)
199 202
 
200 203
         self.assertEqual(D('1.00') + D('2.00'), charge.excl_tax)
204
+
205
+    def test_zero_charge_discount(self):
206
+        # Since Repository.apply_shipping_offer() returns the original
207
+        # shipping method object on a free shipping charge, it's discount()
208
+        # method should be callable and also indicate it won't add discounts.
209
+        basket = factories.create_basket()
210
+        self.assertEqual(D('0.00'), self.standard.discount(basket))
211
+
212
+    def test_zero_charge_with_shipping_discount(self):
213
+        offer = factories.create_offer(
214
+            benefit=Benefit.objects.create(
215
+                type=Benefit.SHIPPING_FIXED_PRICE, value=1),
216
+        )
217
+        basket = factories.create_basket()
218
+        Applicator().apply_offers(basket, [offer])
219
+
220
+        # Similar to test_zero_charge_discount(),
221
+        # but now test how the repository deals with it.
222
+        method = Repository().apply_shipping_offer(
223
+            basket, self.standard, offer)
224
+        self.assertEqual(D('0.00'), method.discount(basket))

Загрузка…
Отмена
Сохранить