From eeed9b2e7214aacd2e1e3152de3d5628434083fb Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Mon, 7 May 2018 06:25:50 +0530 Subject: [PATCH] discount name in templates --- .../templates/datacenterlight/order_detail.html | 4 ++-- datacenterlight/views.py | 2 +- hosting/templates/hosting/order_detail.html | 6 +++--- hosting/views.py | 7 ++++--- utils/hosting_utils.py | 7 +++++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 3b269377..1bedbb44 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -79,8 +79,8 @@ {% if vm.discount > 0 %}

{%trans "Discount" as discount_name %} - {{ vm_pricing.discount_name|default:discount_name }}: - - {{ vm_pricing.discount_amount }} CHF + {{ vm.discount.name|default:discount_name }}: + - {{ discount.amount }} CHF

{% endif %}

diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 8f4c886f..79411fbb 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -172,7 +172,7 @@ class IndexView(CreateView): 'vat': vat, 'vat_percent': vat_percent, 'discount': discount, - 'total_price': price + vat - discount, + 'total_price': price + vat - discount.amount, 'pricing_name': vm_pricing_name } request.session['specs'] = specs diff --git a/hosting/templates/hosting/order_detail.html b/hosting/templates/hosting/order_detail.html index ec50528d..1ed75bd9 100644 --- a/hosting/templates/hosting/order_detail.html +++ b/hosting/templates/hosting/order_detail.html @@ -138,11 +138,11 @@ {{vm.vat|floatformat:2|intcomma}} CHF

{% endif %} - {% if vm_pricing.discount_amount %} + {% if vm.discount > 0 %}

{%trans "Discount" as discount_name %} - {{ vm_pricing.discount_name|default:discount_name }}: - - {{ vm_pricing.discount_amount }} CHF + {{ vm.discount.name|default:discount_name }}: + - {{ discount.amount }} CHF

{% endif %}

diff --git a/hosting/views.py b/hosting/views.py index 99897841..7b3cc357 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -764,7 +764,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): context['vm']['price'] = price context['vm']['discount'] = discount 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() except VMDetail.DoesNotExist: try: @@ -784,7 +784,8 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): context['vm']['price'] = price context['vm']['discount'] = discount context['vm']['vat_percent'] = vat_percent - context['vm']['total_price'] = price + vat - discount + context['vm']['total_price'] = price + \ + vat - discount.amount except WrongIdError: messages.error( self.request, @@ -1084,7 +1085,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View): 'price': price, 'vat': vat, 'vat_percent': vat_percent, - 'total_price': price + vat - discount, + 'total_price': price + vat - discount.amount, 'pricing_name': vm_pricing_name } diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 9e96634f..36964867 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -123,5 +123,8 @@ def get_vm_price_with_vat(cpu, memory, ssd_size, hdd_size=0, cents = decimal.Decimal('.01') price = price.quantize(cents, decimal.ROUND_HALF_UP) vat = vat.quantize(cents, decimal.ROUND_HALF_UP) - discount = pricing.discount_amount - return float(price), float(vat), float(vat_percent), float(discount) + discount = { + 'name': pricing.discount_name, + 'amount': float(pricing.discount_amount), + } + return float(price), float(vat), float(vat_percent), discount