Commits

Luke Plant committed e18354b

Implemented 'pay' view for bookings.

Dummy Paypal buttons at the moment.

  • Participants
  • Parent commits 5ea9bd5
  • Branches bookings

Comments (0)

Files changed (3)

cciw/bookings/models.py

             out.append("(empty)")
         return u", ".join(out)
 
+    # Business methods:
+
+    def get_balance(self):
+        total = self.bookings.filter(state=BOOKING_BOOKED).aggregate(models.Sum('amount_due'))['amount_due__sum']
+        if total is None:
+            total = Decimal('0.00')
+        return total - self.total_received
+
 
 class BookingManager(models.Manager):
     use_for_related_fields = True

cciw/bookings/tests.py

 
 
 class TestListBookings(CreatePlaceMixin, TestCase):
+    # This includes tests for most of the business logic
 
     fixtures = ['basic.json']
 
         self.assertContains(resp2, "Places were not booked due to modifications made")
 
 
+class TestPay(CreatePlaceMixin, TestCase):
+
+    fixtures = ['basic.json']
+
+    url = reverse('cciw.bookings.views.list_bookings')
+
+    def test_balance_empty(self):
+        self.login()
+        resp = self.client.get(reverse('cciw.bookings.views.pay'))
+        self.assertContains(resp, '£0.00')
+
+    def test_balance_after_booking(self):
+        self.login()
+        self.create_place()
+        self.create_place()
+        acc = BookingAccount.objects.get(email=self.email)
+        acc.bookings.all().update(state=BOOKING_BOOKED)
+
+        resp = self.client.get(reverse('cciw.bookings.views.pay'))
+
+        # 2 places:
+        expected_price = 2 * Price.objects.get(year=get_thisyear(),
+                                               price_type=PRICE_FULL).price
+        self.assertContains(resp, '£%s' % expected_price)

cciw/bookings/views.py

                                "to the details. Please check the details and try again.")
             else:
                 if book_basket_now(basket_bookings):
+                    messages.info(request, "Places booked!")
                     return HttpResponseRedirect(reverse('cciw.bookings.views.pay'))
                 else:
                     messages.error(request, "These places cannot be booked for the reasons "
         return self.get(request, *args, **kwargs)
 
 
+class BookingPay(DefaultMetaData, TemplateView):
+    metadata_title = "Booking - Pay"
+    template_name = "cciw/bookings/pay.html"
+
+    def get(self, request):
+        acc = self.request.booking_account
+        self.context['balance'] = acc.get_balance()
+        self.context['account_id'] = acc.id
+        return super(BookingPay, self).get(request)
+
+
 index = BookingIndex.as_view()
 start = BookingStart.as_view()
 email_sent = BookingEmailSent.as_view()
 add_place = booking_account_required(BookingAddPlace.as_view())
 edit_place = booking_account_required(BookingEditPlace.as_view())
 list_bookings = booking_account_required(BookingListBookings.as_view())
-pay = lambda: None
+pay = booking_account_required(BookingPay.as_view())