diff --git a/hosting/migrations/0053_auto_20190415_1952.py b/hosting/migrations/0053_auto_20190415_1952.py new file mode 100644 index 00000000..9a8a9c3d --- /dev/null +++ b/hosting/migrations/0053_auto_20190415_1952.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2019-04-15 19:52 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('hosting', '0052_hostingbilllineitem'), + ] + + operations = [ + migrations.AlterField( + model_name='monthlyhostingbill', + name='order', + field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, to='hosting.HostingOrder'), + ), + ] diff --git a/hosting/models.py b/hosting/models.py index ed6329b8..12ff687c 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -240,7 +240,10 @@ class MonthlyHostingBill(AssignPermissionsMixin, models.Model): Corresponds to Invoice object of Stripe """ customer = models.ForeignKey(StripeCustomer) - order = models.ForeignKey(HostingOrder) + order = models.ForeignKey( + HostingOrder, null=True, blank=True, default=None, + on_delete=models.SET_NULL + ) created = models.DateTimeField(help_text="When the invoice was created") receipt_number = models.CharField( help_text="The receipt number that is generated on Stripe", @@ -274,9 +277,15 @@ class MonthlyHostingBill(AssignPermissionsMixin, models.Model): if len(args['subscription_ids_csv']) > 0: sub_ids = [sub_id.strip() for sub_id in args['subscription_ids_csv'].split(",")] if len(sub_ids) == 1: - args['order'] = HostingOrder.objects.get( - subscription_id=sub_ids[0] - ) + try: + args['order'] = HostingOrder.objects.get( + subscription_id=sub_ids[0] + ) + except HostingOrder.DoesNotExist as dne: + logger.error("Hosting order for {} doesn't exist".format( + sub_ids[0] + )) + args['order'] = None else: logger.debug( "More than one subscriptions"