[hosting/bill] Skip creating MHB for invoices that have been imported already
This commit is contained in:
		
					parent
					
						
							
								cd47af23f1
							
						
					
				
			
			
				commit
				
					
						94d5c34152
					
				
			
		
					 1 changed files with 6 additions and 1 deletions
				
			
		|  | @ -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) | ||||||
|                     ) |                     ) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue