Show correct period start and period end in invoice list

Previously, we used to take the first element in the bill line
item, for invoice start and end date. However, it can be faulty in
cases where the first item does not represent a VM itself (which
we are sure has a monthly subscription and a correct start and end
dates)
This commit is contained in:
PCoder 2019-04-22 11:08:53 +02:00
parent a5188a7ab0
commit 965cc3adf9
3 changed files with 9 additions and 2 deletions

View File

@ -521,6 +521,7 @@ class HostingBillLineItem(AssignPermissionsMixin, models.Model):
)
return item_detail
class VMDetail(models.Model):
user = models.ForeignKey(CustomUser)
vm_id = models.IntegerField(default=0)

View File

@ -31,7 +31,7 @@
<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' %}">{{ line_items_to_show.0.period_start | date:'Y-m-d' }} &mdash; {{ line_items_to_show.0.period_end | date:'Y-m-d' }}</td>
<td class="xs-td-inline" data-header="{% trans 'Period' %}">{{ period_start | date:'Y-m-d' }} &mdash; {{ 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">

View File

@ -1190,7 +1190,13 @@ class InvoiceListView(LoginRequiredMixin, ListView):
try:
vm_detail = VMDetail.objects.get(vm_id=mhb.order.vm_id)
ips_dict[mhb.invoice_number] = [vm_detail.ipv6, vm_detail.ipv4]
line_items_dict[mhb.invoice_number] = HostingBillLineItem.objects.filter(monthly_hosting_bill=mhb)
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
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(