Attempt to show relevant lines when we have more than 1 line item

This commit is contained in:
PCoder 2019-04-20 15:20:55 +02:00
parent 3fbc4528d9
commit e782d27739
2 changed files with 81 additions and 68 deletions

View File

@ -89,6 +89,15 @@
<div>
<h4>{% trans "Invoice summary" %}</h4>
{% if vm %}
{% if line_items %}
<table>
<tr><th>Product</th><th>Period</th><th>Quantity</th><th>Unit Price</th><th>Total</th></tr>
{% for line_item in line_items %}
<tr><td>{% if line_item.description|len > 0 %}{{line_item.description}}{% else %}{{line_item.stripe_plan.stripe_plan_id}}{% endif %}</td><td>{{ line_item.period_start | date:'Y-m-d' }} &mdash; {{ line_item.period_end | date:'Y-m-d' }}</td><td>{{line_item.quantity}}</td><td>{{line_item.unit_amount}}</td><td>{{line_item.amount}}</td></tr>
{% endfor %}
<tr><td colspan="4">Grand Total</td><td>{{total_in_chf}}</td></tr>
</table>
{% else %}
<p>
<strong>{% trans "Product" %}:</strong>&nbsp;
{% if vm.name %}
@ -163,6 +172,7 @@
</p>
</div>
</div>
{% endif %}
{% else %}
<p>
<strong>{% trans "Product" %}:</strong>&nbsp;

View File

@ -1322,6 +1322,9 @@ class InvoiceDetailView(LoginRequiredMixin, DetailView):
context['total_in_chf'] = obj.total_in_chf()
context['invoice_number'] = obj.invoice_number
context['discount_on_stripe'] = obj.discount_in_chf()
if obj.lines_data_count > 1:
# special case, we pass the details of each of the line items
context['line_items'] = obj.hostingbilllineitem_set.all()
return context
else:
raise Http404