Selaa lähdekoodia

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 vuotta sitten
vanhempi
commit
d203c07355
No account linked to committer's email address

+ 3
- 0
src/oscar/apps/dashboard/offers/forms.py Näytä tiedosto

74
         """
74
         """
75
         instance = super().save(*args, **kwargs)
75
         instance = super().save(*args, **kwargs)
76
         if instance.id:
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
             instance.combinations.clear()
80
             instance.combinations.clear()
78
             for offer in self.cleaned_data['combinations']:
81
             for offer in self.cleaned_data['combinations']:
79
                 if offer != instance:
82
                 if offer != instance:

+ 21
- 0
tests/functional/dashboard/test_offer.py Näytä tiedosto

227
         self.assertFalse('range' in condition_page.errors)
227
         self.assertFalse('range' in condition_page.errors)
228
         self.assertEqual(len(condition_page.errors), 0)
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
 class TestOfferListSearch(testcases.WebTestCase):
252
 class TestOfferListSearch(testcases.WebTestCase):
232
     is_staff = True
253
     is_staff = True

Loading…
Peruuta
Tallenna