Commits

Luke Plant  committed ba10be0

Added warning for booking secretary that shows the correct price

  • Participants
  • Parent commits c338a45
  • Branches bookings

Comments (0)

Files changed (2)

File cciw/bookings/models.py

+# -*- coding: utf-8 -*-
 from datetime import datetime, date, timedelta
 from decimal import Decimal
 import os
         return self.state == BOOKING_BOOKED and self.booking_expires is None
     confirmed_booking.boolean = True
 
+    def expected_amount_due(self):
+        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
+        return amount
+
     def auto_set_amount_due(self):
         if self.price_type == PRICE_CUSTOM:
             if self.amount_due is None:
                 self.amount_due = Decimal('0.00')
         else:
-            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
+            self.amount_due = self.expected_amount_due()
 
     def get_booking_problems(self, booking_sec=False):
         """
 
                 warnings.append(warning)
 
+        if booking_sec and self.price_type != PRICE_CUSTOM:
+            expected_amount = self.expected_amount_due()
+            if self.amount_due != expected_amount:
+                errors.append(u"The 'amount due' is not the expected value of £%s." % expected_amount)
 
         return (errors, warnings)
 

File cciw/bookings/tests.py

                         problems)
 
 
+    def test_booking_problems_price_check(self):
+        # Test that the price is checked.
+        # This is a check that is only run for booking secretary
+        self.add_prices()
+        acc1 = BookingAccount.objects.create(email="foo@foo.com",
+                                             post_code="ABC",
+                                             name="Mr Foo")
+        self.client.login(username=BOOKING_SEC_USERNAME, password=BOOKING_SEC_PASSWORD)
+
+        data = self.place_details.copy()
+        data['account'] = str(acc1.id)
+        data['created_0'] = '1970-01-01'
+        data['created_1'] = '00:00:00'
+        data['state'] = BOOKING_BOOKED
+        data['amount_due'] = '0.00'
+        data['price_type'] = PRICE_FULL
+        resp = self.client.post(reverse('cciw.bookings.views.booking_problems_json'),
+                                data)
+
+        json = simplejson.loads(resp.content)
+        problems = json['problems']
+        self.assertTrue(any(p.startswith("The 'amount due' is not the expected value of ")
+                            for p in problems))
+
+
 class TestAccountOverview(CreatePlaceMixin, TestCase):
 
     fixtures = ['basic.json']