Ver código fonte

Fix combination offer removal bug (#4017)

* fix :bug: remove combination offer in both offers

* feat :star: add test to check offer removal from combinations
master
Samar Hassan 2 anos atrás
pai
commit
d203c07355
Nenhuma conta vinculada ao e-mail do autor do commit

+ 3
- 0
src/oscar/apps/dashboard/offers/forms.py Ver arquivo

@@ -74,6 +74,9 @@ class RestrictionsForm(forms.ModelForm):
74 74
         """
75 75
         instance = super().save(*args, **kwargs)
76 76
         if instance.id:
77
+            for offer in instance.combinations.all():
78
+                if offer not in self.cleaned_data['combinations']:
79
+                    offer.combinations.remove(instance)
77 80
             instance.combinations.clear()
78 81
             for offer in self.cleaned_data['combinations']:
79 82
                 if offer != instance:

+ 21
- 0
tests/functional/dashboard/test_offer.py Ver arquivo

@@ -227,6 +227,27 @@ class TestAnAdmin(testcases.WebTestCase):
227 227
         self.assertFalse('range' in condition_page.errors)
228 228
         self.assertEqual(len(condition_page.errors), 0)
229 229
 
230
+    def test_remove_offer_from_combinations(self):
231
+        offer_a = factories.create_offer("Offer A")
232
+        offer_b = factories.create_offer("Offer B")
233
+        offer_b.exclusive = False
234
+        offer_b.save()
235
+
236
+        restrictions_page = self.get(reverse(
237
+            'dashboard:offer-restrictions', kwargs={'pk': offer_a.pk}))
238
+        restrictions_page.form['exclusive'] = False
239
+        restrictions_page.form['combinations'] = [offer_b.id]
240
+        restrictions_page.form.submit()
241
+
242
+        self.assertIn(offer_a, offer_b.combinations.all())
243
+
244
+        restrictions_page = self.get(reverse(
245
+            'dashboard:offer-restrictions', kwargs={'pk': offer_a.pk}))
246
+        restrictions_page.form['combinations'] = []
247
+        restrictions_page.form.submit()
248
+
249
+        self.assertNotIn(offer_a, offer_b.combinations.all())
250
+
230 251
 
231 252
 class TestOfferListSearch(testcases.WebTestCase):
232 253
     is_staff = True

Carregando…
Cancelar
Salvar