discount name in templates

This commit is contained in:
Arvind Tiwari 2018-05-07 06:25:50 +05:30
parent 2ff8c25034
commit eeed9b2e72
5 changed files with 15 additions and 11 deletions

View file

@ -79,8 +79,8 @@
{% if vm.discount > 0 %} {% if vm.discount > 0 %}
<p class="text-primary"> <p class="text-primary">
{%trans "Discount" as discount_name %} {%trans "Discount" as discount_name %}
<span>{{ vm_pricing.discount_name|default:discount_name }}: </span> <span>{{ vm.discount.name|default:discount_name }}: </span>
<span class="pull-right">- {{ vm_pricing.discount_amount }} CHF</span> <span class="pull-right">- {{ discount.amount }} CHF</span>
</p> </p>
{% endif %} {% endif %}
<p> <p>

View file

@ -172,7 +172,7 @@ class IndexView(CreateView):
'vat': vat, 'vat': vat,
'vat_percent': vat_percent, 'vat_percent': vat_percent,
'discount': discount, 'discount': discount,
'total_price': price + vat - discount, 'total_price': price + vat - discount.amount,
'pricing_name': vm_pricing_name 'pricing_name': vm_pricing_name
} }
request.session['specs'] = specs request.session['specs'] = specs

View file

@ -138,11 +138,11 @@
<span class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</span> <span class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</span>
</p> </p>
{% endif %} {% endif %}
{% if vm_pricing.discount_amount %} {% if vm.discount > 0 %}
<p class="text-primary"> <p class="text-primary">
{%trans "Discount" as discount_name %} {%trans "Discount" as discount_name %}
<span>{{ vm_pricing.discount_name|default:discount_name }}: </span> <span>{{ vm.discount.name|default:discount_name }}: </span>
<span class="pull-right">- {{ vm_pricing.discount_amount }} CHF</span> <span class="pull-right">- {{ discount.amount }} CHF</span>
</p> </p>
{% endif %} {% endif %}
<p> <p>

View file

@ -764,7 +764,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView):
context['vm']['price'] = price context['vm']['price'] = price
context['vm']['discount'] = discount context['vm']['discount'] = discount
context['vm']['vat_percent'] = vat_percent context['vm']['vat_percent'] = vat_percent
context['vm']['total_price'] = price + vat - discount context['vm']['total_price'] = price + vat - discount.amount
context['subscription_end_date'] = vm_detail.end_date() context['subscription_end_date'] = vm_detail.end_date()
except VMDetail.DoesNotExist: except VMDetail.DoesNotExist:
try: try:
@ -784,7 +784,8 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView):
context['vm']['price'] = price context['vm']['price'] = price
context['vm']['discount'] = discount context['vm']['discount'] = discount
context['vm']['vat_percent'] = vat_percent context['vm']['vat_percent'] = vat_percent
context['vm']['total_price'] = price + vat - discount context['vm']['total_price'] = price + \
vat - discount.amount
except WrongIdError: except WrongIdError:
messages.error( messages.error(
self.request, self.request,
@ -1084,7 +1085,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
'price': price, 'price': price,
'vat': vat, 'vat': vat,
'vat_percent': vat_percent, 'vat_percent': vat_percent,
'total_price': price + vat - discount, 'total_price': price + vat - discount.amount,
'pricing_name': vm_pricing_name 'pricing_name': vm_pricing_name
} }

View file

@ -123,5 +123,8 @@ def get_vm_price_with_vat(cpu, memory, ssd_size, hdd_size=0,
cents = decimal.Decimal('.01') cents = decimal.Decimal('.01')
price = price.quantize(cents, decimal.ROUND_HALF_UP) price = price.quantize(cents, decimal.ROUND_HALF_UP)
vat = vat.quantize(cents, decimal.ROUND_HALF_UP) vat = vat.quantize(cents, decimal.ROUND_HALF_UP)
discount = pricing.discount_amount discount = {
return float(price), float(vat), float(vat_percent), float(discount) 'name': pricing.discount_name,
'amount': float(pricing.discount_amount),
}
return float(price), float(vat), float(vat_percent), discount