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:
parent
a5188a7ab0
commit
965cc3adf9
3 changed files with 9 additions and 2 deletions
|
@ -521,6 +521,7 @@ class HostingBillLineItem(AssignPermissionsMixin, models.Model):
|
||||||
)
|
)
|
||||||
return item_detail
|
return item_detail
|
||||||
|
|
||||||
|
|
||||||
class VMDetail(models.Model):
|
class VMDetail(models.Model):
|
||||||
user = models.ForeignKey(CustomUser)
|
user = models.ForeignKey(CustomUser)
|
||||||
vm_id = models.IntegerField(default=0)
|
vm_id = models.IntegerField(default=0)
|
||||||
|
|
|
@ -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 '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>
|
<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 %}
|
{% 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' }} — {{ 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' }} — {{ period_end | date:'Y-m-d' }}</td>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
<td class="xs-td-inline" data-header="{% trans 'Amount' %}">{{ invoice.total_in_chf|floatformat:2|intcomma }}</td>
|
<td class="xs-td-inline" data-header="{% trans 'Amount' %}">{{ invoice.total_in_chf|floatformat:2|intcomma }}</td>
|
||||||
<td class="text-right last-td">
|
<td class="text-right last-td">
|
||||||
|
|
|
@ -1190,7 +1190,13 @@ class InvoiceListView(LoginRequiredMixin, ListView):
|
||||||
try:
|
try:
|
||||||
vm_detail = VMDetail.objects.get(vm_id=mhb.order.vm_id)
|
vm_detail = VMDetail.objects.get(vm_id=mhb.order.vm_id)
|
||||||
ips_dict[mhb.invoice_number] = [vm_detail.ipv6, vm_detail.ipv4]
|
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:
|
except VMDetail.DoesNotExist as dne:
|
||||||
ips_dict[mhb.invoice_number] = ['--']
|
ips_dict[mhb.invoice_number] = ['--']
|
||||||
logger.debug("VMDetail for {} doesn't exist".format(
|
logger.debug("VMDetail for {} doesn't exist".format(
|
||||||
|
|
Loading…
Reference in a new issue