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

Allow for children to be explicitly included in ranges.

master
John Parton 11 лет назад
Родитель
Сommit
5b2b50e112
2 измененных файлов: 23 добавлений и 9 удалений
  1. 3
    6
      src/oscar/apps/offer/abstract_models.py
  2. 20
    3
      tests/integration/offer/range_tests.py

+ 3
- 6
src/oscar/apps/offer/abstract_models.py Просмотреть файл

824
         Default display_order for a new product in the range is 0; this puts
824
         Default display_order for a new product in the range is 0; this puts
825
         the product at the top of the list.
825
         the product at the top of the list.
826
         """
826
         """
827
-        if product.is_child:
828
-            raise ValueError(
829
-                "Ranges can only contain parent and stand-alone products.")
830
 
827
 
831
         initial_order = display_order or 0
828
         initial_order = display_order or 0
832
         RangeProduct = get_model('offer', 'RangeProduct')
829
         RangeProduct = get_model('offer', 'RangeProduct')
851
         """
848
         """
852
         Check whether the passed product is part of this range.
849
         Check whether the passed product is part of this range.
853
         """
850
         """
854
-        # Child products are never part of the range, but the parent may be.
855
-        if product.is_child:
856
-            product = product.parent
857
 
851
 
858
         # Delegate to a proxy class if one is provided
852
         # Delegate to a proxy class if one is provided
859
         if self.proxy:
853
         if self.proxy:
867
         if product.product_class_id in self._class_ids():
861
         if product.product_class_id in self._class_ids():
868
             return True
862
             return True
869
         included_product_ids = self._included_product_ids()
863
         included_product_ids = self._included_product_ids()
864
+        # If the product's parent is in the range, the child is automatically included as well
865
+        if product.is_child and product.parent.id in included_product_ids:
866
+            return True
870
         if product.id in included_product_ids:
867
         if product.id in included_product_ids:
871
             return True
868
             return True
872
         test_categories = self.included_categories.all()
869
         test_categories = self.included_categories.all()

+ 20
- 3
tests/integration/offer/range_tests.py Просмотреть файл

28
         self.assertFalse(self.range.contains_product(self.prod))
28
         self.assertFalse(self.range.contains_product(self.prod))
29
 
29
 
30
 
30
 
31
+class TestChildRange(TestCase):
32
+
33
+    def setUp(self):
34
+        self.range = models.Range.objects.create(
35
+            name='Child-specific range', includes_all_products=False)
36
+        self.parent = create_product(structure='parent')
37
+        self.child1 = create_product(structure='child', parent=self.parent)
38
+        self.child2 = create_product(structure='child', parent=self.parent)
39
+        self.range.add_product(self.child1)
40
+
41
+    def test_includes_child(self):
42
+        self.assertTrue(self.range.contains_product(self.child1))
43
+
44
+    def test_does_not_include_parent(self):
45
+        self.assertFalse(self.range.contains_product(self.parent))
46
+
47
+    def test_does_not_include_sibling(self):
48
+        self.assertFalse(self.range.contains_product(self.child2))
49
+
50
+
31
 class TestPartialRange(TestCase):
51
 class TestPartialRange(TestCase):
32
 
52
 
33
     def setUp(self):
53
     def setUp(self):
50
         self.assertTrue(self.range.contains_product(self.parent))
70
         self.assertTrue(self.range.contains_product(self.parent))
51
         self.assertTrue(self.range.contains_product(self.child))
71
         self.assertTrue(self.range.contains_product(self.child))
52
 
72
 
53
-    def test_cant_add_child_product(self):
54
-        self.assertRaises(ValueError, self.range.add_product, self.child)
55
-
56
     def test_included_class_with_exception(self):
73
     def test_included_class_with_exception(self):
57
         self.range.classes.add(self.parent.get_product_class())
74
         self.range.classes.add(self.parent.get_product_class())
58
         self.range.excluded_products.add(self.parent)
75
         self.range.excluded_products.add(self.parent)

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