From 44ffd042a64d5505660a4e2b5542b02a5e26afb6 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 20 Apr 2019 10:00:50 +0200 Subject: [PATCH] Obtain vm_id from multiple line items - Remove empty string from VM_IDs string - If more than one is present, check all of them are the same If same return, the unique value Else return none, as we don't handle this case --- hosting/models.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hosting/models.py b/hosting/models.py index bb61908e..a113b80a 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -390,14 +390,18 @@ class MonthlyHostingBill(AssignPermissionsMixin, models.Model): if len(self.lines_meta_data_csv) > 0: vm_ids = [vm_id.strip() for vm_id in self.lines_meta_data_csv.split(",")] - if len(vm_ids) == 1: - return vm_ids[0] + unique_vm_ids=set(vm_ids) + unique_vm_ids.discard("") + if len(unique_vm_ids) == 1: + vm_id = unique_vm_ids.pop() + logger.debug("Getting invoice for {}".format(vm_id)) + return vm_id else: logger.debug( "More than one VM_ID" "for MonthlyHostingBill {}".format(self.invoice_id) ) - logger.debug("VM_IDS={}".format(','.join(vm_ids))) + logger.debug("VM_IDS={}".format(unique_vm_ids)) return return_value def get_period_start(self):