Repository: carpentries/amy

Issue:
More enumeration values for invoicing status
1.  "not invoiced for historical reasons" (because some workshops took place before we started charging)
2.  "not invoiced because of partnership" (which will cover many train-the-trainer events).

@maneesha can you think of others?



Discussion:
Yes, I've wanted to put in a similar issue myself - we should have had option 2 on the list all along (see #469) although I'd call it "Not invoiced because of membership" as both partners and affiliates may not pay fees.

One other situation I've seen come up is that the entire fee was covered by student registration fees but I have marked that as "other arrangements made"  -- they paid via Eventbrite rather than paying an invoice.  If registration fees only covered a portion of the admin fee, they still get an invoice for the difference.

@gvwilson @maneesha do you want it for December release?

Yes please.

@gvwilson and @maneesha:

I plan to add 'not invoiced for historical reasons' for all events with unknown invoice status older than 2014. I also plan on marking them as 'completed' so they won't bother admins anymore. Any objections?

@maneesha I'm sorry that 'Not applicable because partner organization' was not included in the solution for #469, I don't know how that have happened.


Resolving patch:
diff --git a/workshops/migrations/0062_no_invoice_for_historic_events.py b/workshops/migrations/0062_no_invoice_for_historic_events.py
new file mode 100644
--- /dev/null
+++ b/workshops/migrations/0062_no_invoice_for_historic_events.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from datetime import date
+
+from django.db import models, migrations
+
+START_OF_MODERNITY = date(2014, 1, 1)
+
+
+def no_invoice_for_historical_events(apps, schema_editor):
+    """Set invoice status for historical (<2014) events."""
+    Event = apps.get_model('workshops', 'Event')
+    Event.objects \
+        .filter(start__lt=START_OF_MODERNITY, invoice_status='unknown') \
+        .update(invoice_status='ni-historic')
+
+
+def mark_historical_events_completed(apps, schema_editor):
+    """Set invoice status for historical (<2014) events."""
+    Event = apps.get_model('workshops', 'Event')
+    Event.objects \
+        .filter(start__lt=date(2014, 1, 1), completed=False) \
+        .update(completed=True)
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('workshops', '0061_merge'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='event',
+            name='invoice_status',
+            field=models.CharField(verbose_name='Invoice status', blank=True, default='unknown', choices=[('unknown', 'Unknown'), ('invoiced', 'Invoiced'), ('not-invoiced', 'Not invoiced'), ('ni-historic', 'Not invoiced for historical reasons'), ('ni-member', 'Not invoiced because of membership'), ('na-self-org', 'Not applicable because self-organized'), ('na-waiver', 'Not applicable because waiver granted'), ('na-other', 'Not applicable because other arrangements made')], max_length=40),
+        ),
+        migrations.RunPython(no_invoice_for_historical_events),
+        migrations.RunPython(mark_historical_events_completed),
+    ]
diff --git a/workshops/models.py b/workshops/models.py
--- a/workshops/models.py
+++ b/workshops/models.py
@@ -482,6 +482,8 @@ class Event(AssignmentMixin, models.Model):
         ('unknown', 'Unknown'),
         ('invoiced', 'Invoiced'),
         ('not-invoiced', 'Not invoiced'),
+        ('ni-historic', 'Not invoiced for historical reasons'),
+        ('ni-member', 'Not invoiced because of membership'),
         ('na-self-org', 'Not applicable because self-organized'),
         ('na-waiver', 'Not applicable because waiver granted'),
         ('na-other', 'Not applicable because other arrangements made'),


Test patch: