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,80 +89,90 @@
<div> <div>
<h4>{% trans "Invoice summary" %}</h4> <h4>{% trans "Invoice summary" %}</h4>
{% if vm %} {% if vm %}
<p> {% if line_items %}
<strong>{% trans "Product" %}:</strong>&nbsp; <table>
{% if vm.name %} <tr><th>Product</th><th>Period</th><th>Quantity</th><th>Unit Price</th><th>Total</th></tr>
{{ vm.name }} {% for line_item in line_items %}
{% endif %} <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>
</p> {% endfor %}
<div class="row"> <tr><td colspan="4">Grand Total</td><td>{{total_in_chf}}</td></tr>
<div class="col-sm-6"> </table>
{% if period_start %} {% else %}
<p> <p>
<span>{% trans "Period" %}: </span> <strong>{% trans "Product" %}:</strong>&nbsp;
<span> {% if vm.name %}
<span class="locale_date" {{ vm.name }}
data-format="YYYY/MM/DD">{{ period_start|date:'Y-m-d h:i a' }}</span> - <span
class="locale_date" data-format="YYYY/MM/DD">{{ period_end|date:'Y-m-d h:i a' }}</span>
</span>
</p>
{% endif %}
<p>
<span>{% trans "Cores" %}: </span>
{% if vm.cores %}
<strong class="pull-right">{{vm.cores|floatformat}}</strong>
{% else %}
<strong class="pull-right">{{vm.cpu|floatformat}}</strong>
{% endif %} {% endif %}
</p> </p>
<p> <div class="row">
<span>{% trans "Memory" %}: </span> <div class="col-sm-6">
<strong class="pull-right">{{vm.memory}} GB</strong> {% if period_start %}
</p> <p>
<p> <span>{% trans "Period" %}: </span>
<span>{% trans "Disk space" %}: </span> <span>
<strong class="pull-right">{{vm.disk_size}} GB</strong> <span class="locale_date"
</p> data-format="YYYY/MM/DD">{{ period_start|date:'Y-m-d h:i a' }}</span> - <span
</div> class="locale_date" data-format="YYYY/MM/DD">{{ period_end|date:'Y-m-d h:i a' }}</span>
<div class="col-sm-12"> </span>
<hr class="thin-hr"> </p>
</div> {% endif %}
{% if vm.vat > 0 or vm.discount.amount > 0 %} <p>
<div class="col-sm-6"> <span>{% trans "Cores" %}: </span>
<div class="subtotal-price"> {% if vm.cores %}
{% if vm.vat > 0 %} <strong class="pull-right">{{vm.cores|floatformat}}</strong>
<p> {% else %}
<strong>{% trans "Subtotal" %} </strong> <strong class="pull-right">{{vm.cpu|floatformat}}</strong>
<strong class="pull-right">{{vm.price|floatformat:2|intcomma}} {% endif %}
CHF</strong> </p>
</p> <p>
<p> <span>{% trans "Memory" %}: </span>
<small>{% trans "VAT" %} ({{ vm.vat_percent|floatformat:2|intcomma }}%) <strong class="pull-right">{{vm.memory}} GB</strong>
</small> </p>
<strong class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</strong> <p>
</p> <span>{% trans "Disk space" %}: </span>
{% endif %} <strong class="pull-right">{{vm.disk_size}} GB</strong>
{% if vm.discount.amount > 0 %} </p>
<p class="text-primary"> </div>
{%trans "Discount" as discount_name %} <div class="col-sm-12">
<strong>{{ vm.discount.name|default:discount_name }} </strong> <hr class="thin-hr">
<strong class="pull-right">- {{ vm.discount.amount }} CHF</strong> </div>
</p> {% if vm.vat > 0 or vm.discount.amount > 0 %}
<div class="col-sm-6">
<div class="subtotal-price">
{% if vm.vat > 0 %}
<p>
<strong>{% trans "Subtotal" %} </strong>
<strong class="pull-right">{{vm.price|floatformat:2|intcomma}}
CHF</strong>
</p>
<p>
<small>{% trans "VAT" %} ({{ vm.vat_percent|floatformat:2|intcomma }}%)
</small>
<strong class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</strong>
</p>
{% endif %}
{% if vm.discount.amount > 0 %}
<p class="text-primary">
{%trans "Discount" as discount_name %}
<strong>{{ vm.discount.name|default:discount_name }} </strong>
<strong class="pull-right">- {{ vm.discount.amount }} CHF</strong>
</p>
{% endif %}
</div>
</div>
<div class="col-sm-12">
<hr class="thin-hr">
</div>
{% endif %} {% endif %}
<div class="col-sm-6">
<p class="total-price">
<strong>{% trans "Total" %} </strong>
<strong class="pull-right">{% if vm.total_price %}{{vm.total_price|floatformat:2|intcomma}}{% else %}{{vm.price|floatformat:2|intcomma}}{% endif %}
CHF</strong>
</p>
</div>
</div> </div>
</div>
<div class="col-sm-12">
<hr class="thin-hr">
</div>
{% endif %} {% endif %}
<div class="col-sm-6">
<p class="total-price">
<strong>{% trans "Total" %} </strong>
<strong class="pull-right">{% if vm.total_price %}{{vm.total_price|floatformat:2|intcomma}}{% else %}{{vm.price|floatformat:2|intcomma}}{% endif %}
CHF</strong>
</p>
</div>
</div>
{% else %} {% else %}
<p> <p>
<strong>{% trans "Product" %}:</strong>&nbsp; <strong>{% trans "Product" %}:</strong>&nbsp;

View file

@ -1322,6 +1322,9 @@ class InvoiceDetailView(LoginRequiredMixin, DetailView):
context['total_in_chf'] = obj.total_in_chf() context['total_in_chf'] = obj.total_in_chf()
context['invoice_number'] = obj.invoice_number context['invoice_number'] = obj.invoice_number
context['discount_on_stripe'] = obj.discount_in_chf() 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 return context
else: else:
raise Http404 raise Http404