Luke Plant avatar Luke Plant committed b1bec5b

Fixed bug when editing Booking in admin if prices haven't been defined for that year.

Comments (0)

Files changed (1)

cciw/bookings/views.py

     if form.is_valid():
         retval['valid'] = True
         instance = form.save(commit=False)
-        problems, warnings = instance.get_booking_problems(booking_sec=True)
-        retval['problems'] = problems + warnings
+        # We will get errors later on if prices don't exist for the year chosen, so
+        # we check that first.
+        if not Price.objects.filter(year=instance.camp.year,
+                                    price_type=instance.price_type).exists():
+            retval['problems'] = ['Prices have not been set for the year %d' % instance.camp.year]
+        else:
+            problems, warnings = instance.get_booking_problems(booking_sec=True)
+            retval['problems'] = problems + warnings
     else:
         retval['valid'] = False
         retval['errors'] = form.errors
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.