Luke Plant avatar Luke Plant committed 8157482

Added report for bookings needing approval

Comments (0)

Files changed (3)

cciw/bookings/models.py

     def cancelled(self):
         return self.get_query_set().filter(state=BOOKING_CANCELLED)
 
+    def need_approving(self):
+        qs = self.get_query_set().filter(state=BOOKING_INFO_COMPLETE)
+        qs = qs.filter(price_type=PRICE_CUSTOM) | qs.filter(serious_illness=True)
+        return qs
+
 
 class Booking(models.Model):
     account = models.ForeignKey(BookingAccount, related_name='bookings')
     def is_user_editable(self):
         return self.state == BOOKING_INFO_COMPLETE
 
+    @property
+    def is_custom_discount(self):
+        return self.price_type == PRICE_CUSTOM
+
     class Meta:
         ordering = ['-created']
 

cciw/officers/views.py

 def booking_secretary_reports(request, year=None):
     from cciw.bookings.models import SEX_MALE, SEX_FEMALE, Booking, BOOKING_BOOKED, BOOKING_CANCELLED, BookingAccount
     year = int(year)
+
+    # 1. Camps and their booking levels.
+
     camps = Camp.objects.filter(year=year).prefetch_related('bookings')
     # Do some filtering in Python to avoid multiple db hits
     for c in camps:
         c.confirmed_bookings_girls = [b for b in c.confirmed_bookings if b.sex == SEX_FEMALE]
 
 
+    # 2. Online bookings needing attention
+    to_approve = Booking.objects.need_approving().filter(camp__year__exact=year)
+
+    # 3. Fees
     # Duplication of business logic here, for performance:
     payable = BookingAccount.objects.all()
     # Booked or cancelled places are included.
 
     return render(request, 'cciw/officers/booking_secretary_reports.html',
                   {'year': year, 'camps': camps,
-                   'bookings': bookings})
+                   'bookings': bookings,
+                   'to_approve': to_approve})
 
 
 

templates/cciw/officers/booking_secretary_reports.html

 </table>
 
 
+<h2>Bookings needing approval</h2>
+{% if to_approve %}
+<table class="data">
+  <tr>
+    <th>Account</th>
+    <th>Email</th>
+    <th>Phone</th>
+    <th>Camper name</th>
+    <th>Reason</th>
+    <th>Edit</th>
+  </tr>
+
+  {% for b in to_approve %}
+  <tr>
+    <td>{{ b.account.name }}</td>
+    <td>{{ b.account.email }}</td>
+    <td>{{ b.account.phone_number }}</td>
+    <td>{{ b.name }}</td>
+    <td>
+      {% if b.serious_illness %}Serious illness<br/>{% endif %}
+      {% if b.is_custom_discount %}Custom discount<br/>{% endif %}
+    </td>
+    <td><a href="{% url 'admin:bookings_booking_change' b.id %}" rel="external">Edit</a></td>
+  </tr>
+  {% endfor %}
+</table>
+
+{% else %}
+<p>None found.</p>
+{% endif %}
+
+
 <h2>Outstanding fees</h2>
 
 {% if bookings %}
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.