From c29193f6c82d8f282723cf5c2996d5767f26207a Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 4 Nov 2019 12:05:55 +0530 Subject: [PATCH] Fix bugs - fetch_stripe_bills: - fix wrong assigment of strign to num_invoice_created variable - return None (do not handle the case) if we don't have an order --- hosting/management/commands/fetch_stripe_bills.py | 7 ++++++- hosting/models.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/hosting/management/commands/fetch_stripe_bills.py b/hosting/management/commands/fetch_stripe_bills.py index 20f1cbe0..1e4d1ab3 100644 --- a/hosting/management/commands/fetch_stripe_bills.py +++ b/hosting/management/commands/fetch_stripe_bills.py @@ -50,7 +50,12 @@ class Command(BaseCommand): logger.debug("Invoice %s exists already. Not importing." % invoice['invoice_id']) except MonthlyHostingBill.DoesNotExist as dne: logger.debug("Invoice id %s does not exist" % invoice['invoice_id']) - num_invoice_created += 1 if MonthlyHostingBill.create(invoice) is not None else logger.error("Did not import invoice for %s" % str(invoice)) + + if MonthlyHostingBill.create(invoice) is not None: + num_invoice_created += 1 + else: + logger.error("Did not import invoice for %s" + "" % str(invoice)) self.stdout.write( self.style.SUCCESS("Number of invoices imported = %s" % num_invoice_created) ) diff --git a/hosting/models.py b/hosting/models.py index c9ca5efe..2a9bd28d 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -319,7 +319,10 @@ class MonthlyHostingBill(AssignPermissionsMixin, models.Model): logger.debug("Neither subscription id nor vm_id available") logger.debug("Can't import invoice") return None - + if args['order'] is None: + logger.error( + "Order is None for {}".format(args['invoice_id'])) + return None instance = cls.objects.create( created=datetime.utcfromtimestamp( args['created']).replace(tzinfo=pytz.utc),