Browse Source

Rename strategy fetch method to fetch_for_product

More explicit innit.
master
David Winterbottom 12 years ago
parent
commit
c0fcb45a71

+ 2
- 2
oscar/apps/basket/abstract_models.py View File

@@ -178,7 +178,7 @@ class AbstractBasket(models.Model):
178 178
 
179 179
         # Ensure that all lines are the same currency
180 180
         price_currency = self.currency
181
-        stock_info = self.strategy.fetch(product)
181
+        stock_info = self.strategy.fetch_for_product(product)
182 182
         if price_currency and stock_info.price.currency != price_currency:
183 183
             raise ValueError((
184 184
                 "Basket lines must all have the same currency. Proposed "
@@ -728,7 +728,7 @@ class AbstractLine(models.Model):
728 728
         if not hasattr(self, '_info'):
729 729
             # Cache the stockinfo (note that a strategy instance is assigned to
730 730
             # each line by the basket in the all_lines method).
731
-            self._info = self.strategy.fetch(
731
+            self._info = self.strategy.fetch_for_product(
732 732
                 self.product, self.stockrecord)
733 733
         return self._info
734 734
 

+ 2
- 2
oscar/apps/basket/forms.py View File

@@ -83,7 +83,7 @@ class SavedLineForm(forms.ModelForm):
83 83
         else:
84 84
             desired_qty = self.instance.quantity + line.quantity
85 85
 
86
-        result = self.strategy.fetch(self.instance.product)
86
+        result = self.strategy.fetch_for_product(self.instance.product)
87 87
         is_available, reason = result.availability.is_purchase_permitted(
88 88
             quantity=desired_qty)
89 89
         if not is_available:
@@ -173,7 +173,7 @@ class AddToBasketForm(forms.Form):
173 173
         # basket.
174 174
         current_qty = self.basket.product_quantity(product)
175 175
         desired_qty = current_qty + self.cleaned_data.get('quantity', 1)
176
-        result = self.request.strategy.fetch(product)
176
+        result = self.request.strategy.fetch_for_product(product)
177 177
         is_permitted, reason = result.availability.is_purchase_permitted(
178 178
             desired_qty)
179 179
         if not is_permitted:

+ 1
- 1
oscar/apps/basket/middleware.py View File

@@ -166,6 +166,6 @@ class BasketMiddleware(object):
166 166
         line.delete()
167 167
 
168 168
         # Attempt to re-add to basket with the appropriate stockrecord
169
-        stock_info = basket.strategy.fetch(product)
169
+        stock_info = basket.strategy.fetch_for_product(product)
170 170
         if stock_info.stockrecord:
171 171
             basket.add(product, quantity, options=options)

+ 1
- 1
oscar/apps/checkout/views.py View File

@@ -469,7 +469,7 @@ class PaymentDetailsView(OrderPlacementMixin, TemplateView):
469 469
         """
470 470
         strategy = self.request.strategy
471 471
         for line in basket.all_lines():
472
-            result = strategy.fetch(line.product)
472
+            result = strategy.fetch_for_product(line.product)
473 473
             is_permitted, reason = result.availability.is_purchase_permitted(
474 474
                 line.quantity)
475 475
             if not is_permitted:

+ 1
- 1
oscar/apps/customer/alerts/utils.py View File

@@ -83,7 +83,7 @@ def send_product_alerts(product):
83 83
     for alert in alerts:
84 84
         # Check if the product is available to this user
85 85
         strategy = selector.strategy(user=alert.user)
86
-        data = strategy.fetch(product)
86
+        data = strategy.fetch_for_product(product)
87 87
         if not data.availability.is_available_to_buy:
88 88
             continue
89 89
 

+ 1
- 1
oscar/apps/order/abstract_models.py View File

@@ -643,7 +643,7 @@ class AbstractLine(models.Model):
643 643
         else:
644 644
             desired_qty = basket_line.quantity + self.quantity
645 645
 
646
-        result = strategy.fetch(self.product)
646
+        result = strategy.fetch_for_product(self.product)
647 647
         is_available, reason = result.availability.is_purchase_permitted(
648 648
             quantity=desired_qty)
649 649
         if not is_available:

+ 5
- 5
oscar/apps/partner/strategy.py View File

@@ -53,7 +53,7 @@ class Base(object):
53 53
         if request and request.user.is_authenticated():
54 54
             self.user = request.user
55 55
 
56
-    def fetch(self, product, stockrecord=None):
56
+    def fetch_for_product(self, product, stockrecord=None):
57 57
         """
58 58
         Given a product, return a ``StockInfo`` instance.
59 59
 
@@ -61,13 +61,13 @@ class Base(object):
61 61
 
62 62
         - ``price``: a pricing policy object.
63 63
         - ``availability``: an availability policy object.
64
-        - ``stockrecord``: the stockrecord that is being used to calculate prices and
64
+        - ``stockrecord``: the stockrecord that is being used
65 65
 
66 66
         If a stockrecord is passed, return the appropriate ``StockInfo``
67 67
         instance for that product and stockrecord is returned.
68 68
         """
69 69
         raise NotImplementedError(
70
-            "A strategy class must define a fetch method "
70
+            "A strategy class must define a fetch_for_product method "
71 71
             "for returning the availability and pricing "
72 72
             "information."
73 73
         )
@@ -77,7 +77,7 @@ class Base(object):
77 77
         Given a basket line instance, fetch a ``StockInfo`` instance.
78 78
         """
79 79
         # Default to ignoring any basket line options
80
-        return self.fetch(line.product)
80
+        return self.fetch_for_product(line.product)
81 81
 
82 82
 
83 83
 class Structured(Base):
@@ -90,7 +90,7 @@ class Structured(Base):
90 90
     #) An availability policy
91 91
     """
92 92
 
93
-    def fetch(self, product, stockrecord=None):
93
+    def fetch_for_product(self, product, stockrecord=None):
94 94
         """
95 95
         Return the appropriate stockinfo instance.
96 96
 

+ 2
- 2
oscar/apps/search/search_indexes.py View File

@@ -54,14 +54,14 @@ class ProductIndex(indexes.SearchIndex, indexes.Indexable):
54 54
         # (although that is the most common scenario).
55 55
         if obj.has_stockrecords:
56 56
             # Fetch a "default" stockinfo
57
-            result = strategy.fetch(obj)
57
+            result = strategy.fetch_for_product(obj)
58 58
             if result.price.is_tax_known:
59 59
                 return result.price.incl_tax
60 60
             return result.price.excl_tax
61 61
 
62 62
     def prepare_num_in_stock(self, obj):
63 63
         if obj.has_stockrecords:
64
-            result = strategy.fetch(obj)
64
+            result = strategy.fetch_for_product(obj)
65 65
             return result.stockrecord.net_stock_level
66 66
 
67 67
     def get_updated_field(self):

+ 3
- 3
tests/integration/partner/strategy_tests.py View File

@@ -14,13 +14,13 @@ class TestDefaultStrategy(TestCase):
14 14
 
15 15
     def test_no_stockrecords(self):
16 16
         product = factories.create_product()
17
-        info = self.strategy.fetch(product)
17
+        info = self.strategy.fetch_for_product(product)
18 18
         self.assertFalse(info.availability.is_available_to_buy)
19 19
         self.assertIsNone(info.price.incl_tax)
20 20
 
21 21
     def test_one_stockrecord(self):
22 22
         product = factories.create_product(price=D('1.99'), num_in_stock=4)
23
-        info = self.strategy.fetch(product)
23
+        info = self.strategy.fetch_for_product(product)
24 24
         self.assertTrue(info.availability.is_available_to_buy)
25 25
         self.assertEquals(D('1.99'), info.price.excl_tax)
26 26
         self.assertEquals(D('1.99'), info.price.incl_tax)
@@ -31,7 +31,7 @@ class TestDefaultStrategy(TestCase):
31 31
         product = factories.create_product(
32 32
             product_class=product_class,
33 33
             price=D('1.99'), num_in_stock=None)
34
-        info = self.strategy.fetch(product)
34
+        info = self.strategy.fetch_for_product(product)
35 35
         self.assertTrue(info.availability.is_available_to_buy)
36 36
 
37 37
     def test_line_method_is_same_as_product_one(self):

Loading…
Cancel
Save