Commits

Luke Plant committed 5e35e29

Made use of .basket() manager method instead of manual filtering

  • Participants
  • Parent commits a361608
  • Branches bookings

Comments (0)

Files changed (1)

File cciw/bookings/models.py

 
         # 2nd/3rd child discounts
         if self.price_type == PRICE_2ND_CHILD:
-            qs = self.account.bookings.filter(shelved=False, camp__year__exact=self.camp.year)
+            qs = self.account.bookings.basket(self.camp.year)
             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 "
                               u"and choose an appropriate price type.")
 
         if self.price_type == PRICE_3RD_CHILD:
-            qs = self.account.bookings.filter(shelved=False, camp__year__exact=self.camp.year)
+            qs = self.account.bookings.basket(self.camp.year)
             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 "
 
 
         if self.price_type == PRICE_FULL:
-            full_pricers = self.account.bookings.filter(price_type=PRICE_FULL,
-                                                        camp__year__exact=self.camp.year,
-                                                        shelved=False).order_by('name')
+            full_pricers = self.account.bookings.basket(self.camp.year)\
+                .filter(price_type=PRICE_FULL).order_by('name')
             if len(full_pricers) > 1:
                 names = [b.name for b in full_pricers]
                 pretty_names = u', '.join(names[1:]) + u" and " + names[0]
                 warnings.append(warning)
 
         if self.price_type == PRICE_2ND_CHILD:
-            second_childers = self.account.bookings.filter(price_type=PRICE_2ND_CHILD,
-                                                           camp__year__exact=self.camp.year,
-                                                           shelved=False).order_by('name')
+            second_childers = self.account.bookings.basket(self.camp.year)\
+                .filter(price_type=PRICE_2ND_CHILD).order_by('name')
             if len(second_childers) > 1:
                 names = [b.name for b in second_childers]
                 pretty_names = u', '.join(names[1:]) + u" and " + names[0]