Correct the way we get periods for invoices list
This commit is contained in:
parent
965cc3adf9
commit
1ccb4e9790
3 changed files with 10 additions and 8 deletions
|
@ -500,7 +500,8 @@ class HostingBillLineItem(AssignPermissionsMixin, models.Model):
|
|||
:return:
|
||||
"""
|
||||
item_detail = ""
|
||||
if self.metadata is not None and len(self.metadata) > 0:
|
||||
# metadata is a dict; a dict with nothing has two chars at least {}
|
||||
if self.metadata is not None and len(self.metadata) > 2:
|
||||
try:
|
||||
vm_dict = json.loads(self.metadata)
|
||||
item_detail = "VM ID: {}<br/>".format(vm_dict["VM_ID"])
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
<tr>
|
||||
<td class="xs-td-inline" data-header="{% trans 'VM ID' %}">{{ invoice.order.vm_id }}</td>
|
||||
<td class="xs-td-inline" data-header="{% trans 'IP Address' %}">{{ ips|get_value_from_dict:invoice.invoice_number|join:"<br/>" }}</td>
|
||||
{% with line_items|get_value_from_dict:invoice.invoice_number as line_items_to_show %}
|
||||
<td class="xs-td-inline" data-header="{% trans 'Period' %}">{{ period_start | date:'Y-m-d' }} — {{ period_end | date:'Y-m-d' }}</td>
|
||||
{% with period|get_value_from_dict:invoice.invoice_number as period_to_show %}
|
||||
<td class="xs-td-inline" data-header="{% trans 'Period' %}">{{ period_to_show.period_start | date:'Y-m-d' }} — {{ period_to_show.period_end | date:'Y-m-d' }}</td>
|
||||
{% endwith %}
|
||||
<td class="xs-td-inline" data-header="{% trans 'Amount' %}">{{ invoice.total_in_chf|floatformat:2|intcomma }}</td>
|
||||
<td class="text-right last-td">
|
||||
|
|
|
@ -1185,7 +1185,7 @@ class InvoiceListView(LoginRequiredMixin, ListView):
|
|||
customer__user=self.request.user
|
||||
)
|
||||
ips_dict = {}
|
||||
line_items_dict = {}
|
||||
line_item_period_dict = {}
|
||||
for mhb in mhbs:
|
||||
try:
|
||||
vm_detail = VMDetail.objects.get(vm_id=mhb.order.vm_id)
|
||||
|
@ -1193,17 +1193,18 @@ class InvoiceListView(LoginRequiredMixin, ListView):
|
|||
all_line_items = HostingBillLineItem.objects.filter(monthly_hosting_bill=mhb)
|
||||
for line_item in all_line_items:
|
||||
if line_item.get_item_detail_str() != "":
|
||||
context['period_start'] = line_item.period_start
|
||||
context['period_end'] = line_item.period_end
|
||||
line_item_period_dict[mhb.invoice_number] = {
|
||||
"period_start": line_item.period_start,
|
||||
"period_end": line_item.period_end
|
||||
}
|
||||
break
|
||||
line_items_dict[mhb.invoice_number] = all_line_items
|
||||
except VMDetail.DoesNotExist as dne:
|
||||
ips_dict[mhb.invoice_number] = ['--']
|
||||
logger.debug("VMDetail for {} doesn't exist".format(
|
||||
mhb.order.vm_id
|
||||
))
|
||||
context['line_items'] = line_items_dict
|
||||
context['ips'] = ips_dict
|
||||
context['period'] = line_item_period_dict
|
||||
return context
|
||||
|
||||
def get_queryset(self):
|
||||
|
|
Loading…
Reference in a new issue