Merge branch 'feature/6561/fix-fetching-multiple-line-items-same-subscription' into 'master'
Feature/6561/fix fetching multiple line items same subscription See merge request ungleich-public/dynamicweb!695
This commit is contained in:
		
				commit
				
					
						077bd25d4b
					
				
			
		
					 2 changed files with 21 additions and 8 deletions
				
			
		|  | @ -42,9 +42,13 @@ class Command(BaseCommand): | ||||||
|                         exit(1) |                         exit(1) | ||||||
|                     all_invoices = all_invoices_response['response_object'] |                     all_invoices = all_invoices_response['response_object'] | ||||||
|                     self.stdout.write(self.style.SUCCESS("Obtained {} invoices".format(len(all_invoices) if all_invoices is not None else 0))) |                     self.stdout.write(self.style.SUCCESS("Obtained {} invoices".format(len(all_invoices) if all_invoices is not None else 0))) | ||||||
|  |                     num_invoice_created = 0 | ||||||
|                     for invoice in all_invoices: |                     for invoice in all_invoices: | ||||||
|                         invoice['customer'] = user.stripecustomer |                         invoice['customer'] = user.stripecustomer | ||||||
|                         MonthlyHostingBill.create(invoice) |                         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.style.SUCCESS("Number of invoices imported = %s" % num_invoice_created) | ||||||
|  |                     ) | ||||||
|                 else: |                 else: | ||||||
|                     self.stdout.write(self.style.SUCCESS( |                     self.stdout.write(self.style.SUCCESS( | ||||||
|                         'Customer email %s does not have a stripe customer.' % email)) |                         'Customer email %s does not have a stripe customer.' % email)) | ||||||
|  |  | ||||||
|  | @ -273,10 +273,19 @@ class MonthlyHostingBill(AssignPermissionsMixin, models.Model): | ||||||
|         # Try to infer the HostingOrder from subscription id or VM_ID |         # Try to infer the HostingOrder from subscription id or VM_ID | ||||||
|         if len(args['subscription_ids_csv']) > 0: |         if len(args['subscription_ids_csv']) > 0: | ||||||
|             sub_ids = [sub_id.strip() for sub_id in args['subscription_ids_csv'].split(",")] |             sub_ids = [sub_id.strip() for sub_id in args['subscription_ids_csv'].split(",")] | ||||||
|             if len(sub_ids) == 1: |             set_sub_ids = set(sub_ids) | ||||||
|  |             if len(set_sub_ids) == 1: | ||||||
|  |                 # the multiple line items belong to the same subscription | ||||||
|  |                 sub_id = set_sub_ids.pop() | ||||||
|  |                 try: | ||||||
|                     args['order'] = HostingOrder.objects.get( |                     args['order'] = HostingOrder.objects.get( | ||||||
|                     subscription_id=sub_ids[0] |                         subscription_id=sub_id | ||||||
|                     ) |                     ) | ||||||
|  |                 except HostingOrder.DoesNotExist as dne: | ||||||
|  |                     logger.error("Hosting order for {} doesn't exist".format( | ||||||
|  |                         sub_id | ||||||
|  |                     )) | ||||||
|  |                     args['order'] = None | ||||||
|             else: |             else: | ||||||
|                 logger.debug( |                 logger.debug( | ||||||
|                     "More than one subscriptions" |                     "More than one subscriptions" | ||||||
|  | @ -284,7 +293,7 @@ class MonthlyHostingBill(AssignPermissionsMixin, models.Model): | ||||||
|                 ) |                 ) | ||||||
|                 logger.debug("SUB_IDS={}".format(','.join(sub_ids))) |                 logger.debug("SUB_IDS={}".format(','.join(sub_ids))) | ||||||
|                 logger.debug("Not importing invoices") |                 logger.debug("Not importing invoices") | ||||||
|                 return |                 return None | ||||||
|         elif len(args['lines_meta_data_csv']) > 0: |         elif len(args['lines_meta_data_csv']) > 0: | ||||||
|             vm_ids = [vm_id.strip() for vm_id in args['lines_meta_data_csv'].split(",")] |             vm_ids = [vm_id.strip() for vm_id in args['lines_meta_data_csv'].split(",")] | ||||||
|             if len(vm_ids) == 1: |             if len(vm_ids) == 1: | ||||||
|  | @ -296,11 +305,11 @@ class MonthlyHostingBill(AssignPermissionsMixin, models.Model): | ||||||
|                 ) |                 ) | ||||||
|                 logger.debug("VM_IDS={}".format(','.join(vm_ids))) |                 logger.debug("VM_IDS={}".format(','.join(vm_ids))) | ||||||
|                 logger.debug("Not importing invoices") |                 logger.debug("Not importing invoices") | ||||||
|                 return |                 return None | ||||||
|         else: |         else: | ||||||
|             logger.debug("Neither subscription id nor vm_id available") |             logger.debug("Neither subscription id nor vm_id available") | ||||||
|             logger.debug("Can't import invoice") |             logger.debug("Can't import invoice") | ||||||
|             return |             return None | ||||||
| 
 | 
 | ||||||
|         instance = cls.objects.create( |         instance = cls.objects.create( | ||||||
|             created=datetime.utcfromtimestamp( |             created=datetime.utcfromtimestamp( | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue