Commits

Luke Plant committed feff265

Added business logic for South Wales transport surcharge

Comments (0)

Files changed (3)

cciw/bookings/models.py

     (SEX_FEMALE, 'Female'),
 ]
 
-PRICE_FULL, PRICE_2ND_CHILD, PRICE_3RD_CHILD, PRICE_CUSTOM = range(0, 4)
+PRICE_FULL, PRICE_2ND_CHILD, PRICE_3RD_CHILD, PRICE_CUSTOM, PRICE_SOUTH_WALES_TRANSPORT = range(0, 5)
 PRICE_TYPES = [
     (PRICE_FULL,      'Full price'),
     (PRICE_2ND_CHILD, '2nd child discount'),
 ]
 
 # Price types that are used by Price model
-VALUED_PRICE_TYPES = [(v,d) for (v,d) in PRICE_TYPES if v is not PRICE_CUSTOM]
+VALUED_PRICE_TYPES = [(v,d) for (v,d) in PRICE_TYPES if v is not PRICE_CUSTOM] + \
+    [(PRICE_SOUTH_WALES_TRANSPORT, 'South wales transport surcharge')]
+
 
 BOOKING_INFO_COMPLETE, BOOKING_APPROVED, BOOKING_BOOKED = range(0, 3)
 BOOKING_STATES = [
             if self.amount_due is None:
                 self.amount_due = Decimal('0.00')
         else:
-            self.amount_due = Price.objects.get(year=self.camp.year,
-                                                price_type=self.price_type).price
+            amount = Price.objects.get(year=self.camp.year,
+                                       price_type=self.price_type).price
+            if self.south_wales_transport:
+                amount += Price.objects.get(price_type=PRICE_SOUTH_WALES_TRANSPORT,
+                                            year=self.camp.year).price
+            self.amount_due = amount
 
     def get_booking_problems(self):
         """

cciw/bookings/tests.py

 from django.utils import simplejson
 
 from cciw.bookings.models import BookingAccount, Price, Booking
-from cciw.bookings.models import PRICE_FULL, PRICE_2ND_CHILD, PRICE_3RD_CHILD, PRICE_CUSTOM, BOOKING_APPROVED, BOOKING_INFO_COMPLETE, BOOKING_BOOKED
+from cciw.bookings.models import PRICE_FULL, PRICE_2ND_CHILD, PRICE_3RD_CHILD, PRICE_CUSTOM, PRICE_SOUTH_WALES_TRANSPORT, BOOKING_APPROVED, BOOKING_INFO_COMPLETE, BOOKING_BOOKED
 from cciw.cciwmain.common import get_thisyear
 from cciw.cciwmain.models import Camp
 from cciw.cciwmain.tests.mailhelpers import read_email_url
         Price.objects.get_or_create(year=year,
                                     price_type=PRICE_3RD_CHILD,
                                     price=Decimal('50.00'))
+        Price.objects.get_or_create(year=year,
+                                    price_type=PRICE_SOUTH_WALES_TRANSPORT,
+                                    price=Decimal('20.00'))
 
     def create_camp(self):
         # Need to create a Camp that we can choose i.e. is in the future
         # Did we create it?
         self.assertEqual(b.bookings.count(), 1)
 
+        # Check amount_due
+        self.assertEqual(b.bookings.all()[0].amount_due, Price.objects.get(price_type=PRICE_FULL,
+                                                                           year=get_thisyear()).price)
+
+    def test_south_wales_surcharge(self):
+        self.login()
+        self.add_prices()
+        b = BookingAccount.objects.get(email=self.email)
+        camp = Camp.objects.filter(start_date__gte=datetime.now())[0]
+        self.assertEqual(b.bookings.count(), 0)
+
+        data = self.place_details.copy()
+        data['camp'] = camp.id
+        data['south_wales_transport'] = '1'
+        resp = self.client.post(reverse('cciw.bookings.views.add_place'), data)
+        p = Price.objects.get(price_type=PRICE_FULL, year=get_thisyear()).price + \
+            Price.objects.get(price_type=PRICE_SOUTH_WALES_TRANSPORT, year=get_thisyear()).price
+        self.assertEqual(b.bookings.all()[0].amount_due, p)
+
 
 class TestEditPlace(CreatePlaceMixin, TestCase):
 

cciw/bookings/views.py

     """
     When passed a given year, returns True if booking is open.
     """
-    return Price.objects.filter(year=year).count() == 3 and Camp.objects.filter(year=year).exists()
+    return Price.objects.filter(year=year).count() == 4 and Camp.objects.filter(year=year).exists()
 
 is_booking_open_thisyear = lambda: is_booking_open(get_thisyear())