Commits

Luke Plant committed 8157482

Added report for bookings needing approval

  • Participants
  • Parent commits 45f348c
  • Branches bookings

Comments (0)

Files changed (3)

File 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']
 

File 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})
 
 
 

File 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 %}