[hosting/bill] Skip creating MHB for invoices that have been imported already

This commit is contained in:
PCoder 2019-05-13 21:15:38 +02:00
parent cd47af23f1
commit 94d5c34152

View file

@ -45,7 +45,12 @@ class Command(BaseCommand):
num_invoice_created = 0 num_invoice_created = 0
for invoice in all_invoices: for invoice in all_invoices:
invoice['customer'] = user.stripecustomer invoice['customer'] = user.stripecustomer
num_invoice_created += 1 if MonthlyHostingBill.create(invoice) is not None else logger.error("Did not import invoice for %s" % str(invoice)) try:
existing_mhb = MonthlyHostingBill.objects.get(invoice_id=invoice['invoice_id'])
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))
self.stdout.write( self.stdout.write(
self.style.SUCCESS("Number of invoices imported = %s" % num_invoice_created) self.style.SUCCESS("Number of invoices imported = %s" % num_invoice_created)
) )