Explorar el Código

Make value field mandatory for percentage discount benefit.

master
Alexander Gaevsky hace 9 años
padre
commit
8fa4e093b3

+ 3
- 0
src/oscar/apps/offer/abstract_models.py Ver fichero

521
         if not self.range:
521
         if not self.range:
522
             raise exceptions.ValidationError(
522
             raise exceptions.ValidationError(
523
                 _("Percentage benefits require a product range"))
523
                 _("Percentage benefits require a product range"))
524
+        if not self.value:
525
+            raise exceptions.ValidationError(
526
+                _("Percentage discount benefits require a value"))
524
         if self.value > 100:
527
         if self.value > 100:
525
             raise exceptions.ValidationError(
528
             raise exceptions.ValidationError(
526
                 _("Percentage discount cannot be greater than 100"))
529
                 _("Percentage discount cannot be greater than 100"))

+ 13
- 0
tests/integration/offer/percentage_benefit_tests.py Ver fichero

1
 from decimal import Decimal as D
1
 from decimal import Decimal as D
2
 
2
 
3
+from django.core import exceptions
3
 from django.test import TestCase
4
 from django.test import TestCase
4
 import mock
5
 import mock
5
 
6
 
179
         self.assertEqual(1 * D('4.00') * D('0.2'), result.discount)
180
         self.assertEqual(1 * D('4.00') * D('0.2'), result.discount)
180
         self.assertEqual(3, self.basket.num_items_with_discount)
181
         self.assertEqual(3, self.basket.num_items_with_discount)
181
         self.assertEqual(0, self.basket.num_items_without_discount)
182
         self.assertEqual(0, self.basket.num_items_without_discount)
183
+
184
+
185
+class TestAPercentageDiscountBenefit(TestCase):
186
+
187
+    def test_requires_a_benefit_value(self):
188
+        rng = models.Range.objects.create(
189
+            name="", includes_all_products=True)
190
+        benefit = models.Benefit.objects.create(
191
+            type=models.Benefit.PERCENTAGE, range=rng
192
+        )
193
+        with self.assertRaises(exceptions.ValidationError):
194
+            benefit.clean()

Loading…
Cancelar
Guardar