Fallback to obtain VM_ID from order if not in metadata
This commit is contained in:
parent
3c215638f5
commit
d64b6329ab
1 changed files with 53 additions and 40 deletions
|
|
@ -1234,6 +1234,7 @@ class InvoiceDetailView(LoginRequiredMixin, DetailView):
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None):
|
||||||
invoice_id = self.kwargs.get('invoice_id')
|
invoice_id = self.kwargs.get('invoice_id')
|
||||||
|
logger.debug("Getting invoice for %s" % invoice_id)
|
||||||
try:
|
try:
|
||||||
invoice_obj = MonthlyHostingBill.objects.get(
|
invoice_obj = MonthlyHostingBill.objects.get(
|
||||||
invoice_number=invoice_id
|
invoice_number=invoice_id
|
||||||
|
|
@ -1262,6 +1263,16 @@ class InvoiceDetailView(LoginRequiredMixin, DetailView):
|
||||||
|
|
||||||
if obj is not None:
|
if obj is not None:
|
||||||
vm_id = obj.get_vm_id()
|
vm_id = obj.get_vm_id()
|
||||||
|
if vm_id is None:
|
||||||
|
# We did not find it in the metadata, fallback to order
|
||||||
|
if obj.order is not None:
|
||||||
|
vm_id = obj.order.vm_id
|
||||||
|
logger.debug("VM ID from order is %s" % vm_id)
|
||||||
|
else:
|
||||||
|
logger.debug("VM order is None. So, we don't have VM_ID")
|
||||||
|
else:
|
||||||
|
logger.debug("VM ID was set in metadata")
|
||||||
|
if vm_id > 0:
|
||||||
try:
|
try:
|
||||||
# Try to get vm details from database
|
# Try to get vm details from database
|
||||||
vm_detail = VMDetail.objects.get(vm_id=vm_id)
|
vm_detail = VMDetail.objects.get(vm_id=vm_id)
|
||||||
|
|
@ -1314,6 +1325,8 @@ class InvoiceDetailView(LoginRequiredMixin, DetailView):
|
||||||
self.kwargs['error'] = 'WrongIdError'
|
self.kwargs['error'] = 'WrongIdError'
|
||||||
context['error'] = 'WrongIdError'
|
context['error'] = 'WrongIdError'
|
||||||
return context
|
return context
|
||||||
|
else:
|
||||||
|
logger.debug("No VM_ID. So, no details available.")
|
||||||
|
|
||||||
# add context params from monthly hosting bill
|
# add context params from monthly hosting bill
|
||||||
context['period_start'] = obj.get_period_start()
|
context['period_start'] = obj.get_period_start()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue