Repository: carpentries/amy

Issue:
"Not Invoiced" dashboard column not populating correctly
For example 2015-10-05-ucalgary and 2015-10-12-vt are marked  not invoiced on their respective event pages but don't show up in that column on dashboard.



Discussion:
@maneesha the rule for uninvoiced workshop to show up is that they have some admin fee assigned to them. 2015-10-05-ucalgary currently doesn't and thus it won't show up on the dashboard.

Do you want to change that rule?

So the "not invoiced" column on the dashboard is not populated by the event's invoice status being "not invoiced"? 

This is confusing.  I'd want this column to list all events with status = "not invoiced" -- then I know I have to process the invoice or change the status to something else.

@maneesha sure. The rule for now is "anything with not-invoiced status and non-NULL admin fee", but I'll change that for you for v1.1.


Resolving patch:
diff --git a/workshops/models.py b/workshops/models.py
--- a/workshops/models.py
+++ b/workshops/models.py
@@ -411,12 +411,12 @@ def published_events(self):
     def uninvoiced_events(self):
         '''Return a queryset for events that have not yet been invoiced.
 
-        These are events that have an admin fee, are not marked as invoiced, and have occurred.
+        These are marked as uninvoiced, and have occurred.
         Events are sorted oldest first.'''
 
-        return self.past_events().filter(admin_fee__gt=0)\
-                   .exclude(invoice_status='invoiced')\
-                   .order_by('start')
+        return self.past_events().filter(invoice_status='not-invoiced') \
+                                 .order_by('start')
+
 
 class EventManager(models.Manager):
     '''A custom manager which is essentially a proxy for EventQuerySet'''


Test patch:
diff --git a/workshops/test/base.py b/workshops/test/base.py
--- a/workshops/test/base.py
+++ b/workshops/test/base.py
@@ -213,6 +213,15 @@ def _setUpEvents(self):
                                  admin_fee=100,
                                  invoice_status=next(invoice))
 
+        # create a past event that has no admin fee specified, yet it needs
+        # invoice
+        event_start = today + datetime.timedelta(days=-4)
+        Event.objects.create(
+            start=event_start, end=today + datetime.timedelta(days=-1),
+            slug='{:%Y-%m-%d}-past-uninvoiced'.format(event_start),
+            host=test_host, admin_fee=None, invoice_status='not-invoiced',
+        )
+
         # Create an event that started yesterday and ends tomorrow
         # with no fee, and without specifying whether they've been
         # invoiced.
@@ -248,8 +257,7 @@ def _setUpEvents(self):
         self.num_uninvoiced_events = 0
         self.num_upcoming = 0
         for e in Event.objects.all():
-            if (e.admin_fee > 0) and (e.invoice_status == 'not-invoiced') \
-                    and (e.start < today):
+            if e.invoice_status == 'not-invoiced' and e.start < today:
                 self.num_uninvoiced_events += 1
             if e.url and (e.start > today):
                 self.num_upcoming += 1
diff --git a/workshops/test/test_event.py b/workshops/test/test_event.py
--- a/workshops/test/test_event.py
+++ b/workshops/test/test_event.py
@@ -32,8 +32,8 @@ def test_get_uninvoiced_events(self):
         # There should be as many as there are strictly future events.
         assert len(uninvoiced_events) == self.num_uninvoiced_events
 
-        # Check that events with a fee of zero are not in the list of uninvoiced events.
-        assert not any([x for x in uninvoiced_events if x.admin_fee == 0])
+        # Check that events with a fee of zero or None are still on this list
+        assert any([x for x in uninvoiced_events if not x.admin_fee])
 
     def test_get_future_events(self):
         """Test that the events manager can find upcoming events"""
@@ -47,8 +47,7 @@ def test_get_past_events(self):
 
         past_events = Event.objects.past_events()
 
-        # There are 3 past events
-        assert len(past_events) == 8
+        assert len(past_events) == 9
 
         # They should all start with past
         assert all(['past' in e.slug for e in past_events])