Make HostingOrder not mandatory in MonthlyHostingBill

This commit is contained in:
PCoder 2019-04-15 21:53:35 +02:00
parent c081f9e73a
commit eb360c7406
2 changed files with 34 additions and 4 deletions

View file

@ -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'),
),
]

View file

@ -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"