Make HostingOrder not mandatory in MonthlyHostingBill

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

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"