Luke Plant avatar Luke Plant committed 55c0be3

Fixed bug with booking not being allowed incorrectly

Comments (0)

Files changed (2)

cciw/bookings/models.py

         # 2nd/3rd child discounts
         if self.price_type == PRICE_2ND_CHILD:
             qs = self.account.bookings.basket(self.camp.year)
+            qs = qs | self.account.bookings.booked()
             if not qs.filter(price_type=PRICE_FULL).exists():
                 errors.append(u"You cannot use a 2nd child discount unless you have "
                               u"a child at full price. Please edit the place details "
 
         if self.price_type == PRICE_3RD_CHILD:
             qs = self.account.bookings.basket(self.camp.year)
+            qs = qs | self.account.bookings.booked()
             qs = qs.filter(price_type=PRICE_FULL) | qs.filter(price_type=PRICE_2ND_CHILD)
             if qs.count() < 2:
                 errors.append(u"You cannot use a 3rd child discount unless you have "

cciw/bookings/tests.py

         self.assertContains(resp, "You cannot use a 2nd child discount")
         self.assertContains(resp, DISABLED_BOOK_NOW_BTN)
 
+    def test_2nd_child_discount_allowed_if_booked(self):
+        """
+        Test that we can have 2nd child discount if full price
+        place is already booked.
+        """
+        self.login()
+        self.create_place()
+        acc = self.get_account()
+        acc.bookings.update(state=BOOKING_BOOKED)
+
+        self.create_place({'price_type': PRICE_2ND_CHILD,
+                           'first_name': 'Mary'})
+
+        resp = self.client.get(self.url)
+        self.assertContains(resp, ENABLED_BOOK_NOW_BUTTON)
+
     def test_3rd_child_discount_allowed(self):
         self.login()
         self.create_place({'price_type': PRICE_FULL})
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.