From d37a2de6eb5dec8c935b7b4692d87875cf60775a Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 3 Apr 2019 22:48:56 +0200 Subject: [PATCH] Add utility functions --- hosting/models.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/hosting/models.py b/hosting/models.py index 5b48abbf..d58e2fce 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -338,6 +338,33 @@ class MonthlyHostingBill(AssignPermissionsMixin, models.Model): """ return self.total * 0.01 + def discount_in_chf(self): + """ + Returns discount in chf. + + :return: + """ + return self.discount * 0.01 + + def get_vm_id(self): + """ + Returns the VM_ID metadata if set in this MHB else returns None + :return: + """ + return_value = None + 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] + else: + logger.debug( + "More than one VM_ID" + "for MonthlyHostingBill {}".format(self.invoice_id) + ) + logger.debug("VM_IDS=".format(','.join(vm_ids))) + return return_value + class VMDetail(models.Model): user = models.ForeignKey(CustomUser)