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
This commit is contained in:
PCoder 2019-04-20 10:00:50 +02:00
parent 9f13253475
commit 44ffd042a6

View file

@ -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):