浏览代码

Return True in is_tax_known() when the basket is empty (#4166)

* Fix AbstractBasket's is_tax_known() to handle an empty basket

* Fix lint errors

* Added another test for is_tax_known

* Improved clarity of complex expression
master
TopDevPros 2 年前
父节点
当前提交
39e7c8d7d9
没有帐户链接到提交者的电子邮件

+ 6
- 2
src/oscar/apps/basket/abstract_models.py 查看文件

@@ -465,9 +465,13 @@ class AbstractBasket(models.Model):
465 465
     @property
466 466
     def is_tax_known(self):
467 467
         """
468
-        Test if tax values are known for this basket
468
+        Test if tax values are known for this basket.
469
+
470
+        If the basket is empty, then tax values are unknown.
469 471
         """
470
-        return all([line.is_tax_known for line in self.all_lines()])
472
+        return (not self.is_empty) and all(
473
+            [line.is_tax_known for line in self.all_lines()]
474
+        )
471 475
 
472 476
     @property
473 477
     def total_excl_tax(self):

+ 7
- 0
tests/integration/basket/test_models.py 查看文件

@@ -41,6 +41,10 @@ class TestANewBasket(TestCase):
41 41
     def test_has_no_applied_offers(self):
42 42
         self.assertEqual({}, self.basket.applied_offers())
43 43
 
44
+    def test_is_tax_unknown(self):
45
+        self.assertTrue(self.basket.is_empty)
46
+        self.assertFalse(self.basket.is_tax_known)
47
+
44 48
 
45 49
 class TestBasketLine(TestCase):
46 50
     def test_description(self):
@@ -143,6 +147,9 @@ class TestAddingAProductToABasket(TestCase):
143 147
         with self.assertRaises(ValueError):
144 148
             self.basket.add(product)
145 149
 
150
+    def test_is_tax_known(self):
151
+        self.assertTrue(self.basket.is_tax_known)
152
+
146 153
 
147 154
 class TestANonEmptyBasket(TestCase):
148 155
     def setUp(self):

+ 3
- 2
tests/integration/order/test_creator.py 查看文件

@@ -206,6 +206,9 @@ class TestShippingOfferForOrder(TestCase):
206 206
     def setUp(self):
207 207
         self.creator = OrderCreator()
208 208
         self.basket = factories.create_basket(empty=True)
209
+
210
+        # add the product now so we can calculate the correct surcharges
211
+        add_product(self.basket, D("12.00"))
209 212
         self.surcharges = SurchargeApplicator().get_applicable_surcharges(self.basket)
210 213
 
211 214
     def apply_20percent_shipping_offer(self):
@@ -221,7 +224,6 @@ class TestShippingOfferForOrder(TestCase):
221 224
         return offer
222 225
 
223 226
     def test_shipping_offer_is_applied(self):
224
-        add_product(self.basket, D("12.00"))
225 227
         offer = self.apply_20percent_shipping_offer()
226 228
 
227 229
         shipping = FixedPrice(D("5.00"), D("5.00"))
@@ -241,7 +243,6 @@ class TestShippingOfferForOrder(TestCase):
241 243
         self.assertEqual(D("38.00"), order.total_incl_tax)
242 244
 
243 245
     def test_zero_shipping_discount_is_not_created(self):
244
-        add_product(self.basket, D("12.00"))
245 246
         offer = self.apply_20percent_shipping_offer()
246 247
 
247 248
         shipping = Free()

正在加载...
取消
保存