exclude discount from total price
This commit is contained in:
parent
144d885fbd
commit
2ff8c25034
5 changed files with 27 additions and 25 deletions
|
@ -36,22 +36,27 @@ class VMPricing(models.Model):
|
|||
)
|
||||
discount_name = models.CharField(max_length=255, null=True, blank=True)
|
||||
discount_amount = models.DecimalField(
|
||||
max_digits=4, decimal_places=2, default=0
|
||||
max_digits=6, decimal_places=2, default=0
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.name + ' => ' + ' - '.join([
|
||||
display_str = self.name + ' => ' + ' - '.join([
|
||||
'{}/Core'.format(self.cores_unit_price.normalize()),
|
||||
'{}/GB RAM'.format(self.ram_unit_price.normalize()),
|
||||
'{}/GB SSD'.format(self.ssd_unit_price.normalize()),
|
||||
'{}/GB HDD'.format(self.hdd_unit_price.normalize()),
|
||||
'{}% VAT'.format(self.vat_percentage.normalize())
|
||||
if not self.vat_inclusive else 'VAT-Incl',
|
||||
'{} {}'.format(
|
||||
self.discount_amount if self.discount_amount else '',
|
||||
self.discount_name if self.discount_name else 'Discount'
|
||||
),
|
||||
])
|
||||
if self.discount_amount:
|
||||
display_str = ' - '.join([
|
||||
display_str,
|
||||
'{} {}'.format(
|
||||
self.discount_amount,
|
||||
self.discount_name if self.discount_name else 'Discount'
|
||||
)
|
||||
])
|
||||
return display_str
|
||||
|
||||
@classmethod
|
||||
def get_vm_pricing_by_name(cls, name):
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
<span class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</span>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if vm_pricing.discount_amount %}
|
||||
{% if vm.discount > 0 %}
|
||||
<p class="text-primary">
|
||||
{%trans "Discount" as discount_name %}
|
||||
<span>{{ vm_pricing.discount_name|default:discount_name }}: </span>
|
||||
|
|
|
@ -158,7 +158,7 @@ class IndexView(CreateView):
|
|||
)
|
||||
return HttpResponseRedirect(referer_url + "#order_form")
|
||||
|
||||
price, vat, vat_percent = get_vm_price_with_vat(
|
||||
price, vat, vat_percent, discount = get_vm_price_with_vat(
|
||||
cpu=cores,
|
||||
memory=memory,
|
||||
ssd_size=storage,
|
||||
|
@ -171,7 +171,8 @@ class IndexView(CreateView):
|
|||
'price': price,
|
||||
'vat': vat,
|
||||
'vat_percent': vat_percent,
|
||||
'total_price': price + vat,
|
||||
'discount': discount,
|
||||
'total_price': price + vat - discount,
|
||||
'pricing_name': vm_pricing_name
|
||||
}
|
||||
request.session['specs'] = specs
|
||||
|
@ -388,9 +389,6 @@ class OrderConfirmationView(DetailView):
|
|||
request.session.get('billing_address_data')
|
||||
),
|
||||
'cms_integration': get_cms_integration('default'),
|
||||
'vm_pricing': VMPricing.get_vm_pricing_by_name(
|
||||
self.request.session['specs']['pricing_name']
|
||||
),
|
||||
}
|
||||
return render(request, self.template_name, context)
|
||||
|
||||
|
|
|
@ -655,7 +655,7 @@ class PaymentVMView(LoginRequiredMixin, FormView):
|
|||
'stripe_key': settings.STRIPE_API_PUBLIC_KEY,
|
||||
'vm_pricing': VMPricing.get_vm_pricing_by_name(
|
||||
self.request.session['specs']['pricing_name']
|
||||
)
|
||||
),
|
||||
})
|
||||
|
||||
return context
|
||||
|
@ -753,7 +753,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView):
|
|||
context['vm'] = vm_detail.__dict__
|
||||
context['vm']['name'] = '{}-{}'.format(
|
||||
context['vm']['configuration'], context['vm']['vm_id'])
|
||||
price, vat, vat_percent = get_vm_price_with_vat(
|
||||
price, vat, vat_percent, discount = get_vm_price_with_vat(
|
||||
cpu=context['vm']['cores'],
|
||||
ssd_size=context['vm']['disk_size'],
|
||||
memory=context['vm']['memory'],
|
||||
|
@ -762,8 +762,9 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView):
|
|||
)
|
||||
context['vm']['vat'] = vat
|
||||
context['vm']['price'] = price
|
||||
context['vm']['discount'] = discount
|
||||
context['vm']['vat_percent'] = vat_percent
|
||||
context['vm']['total_price'] = price + vat
|
||||
context['vm']['total_price'] = price + vat - discount
|
||||
context['subscription_end_date'] = vm_detail.end_date()
|
||||
except VMDetail.DoesNotExist:
|
||||
try:
|
||||
|
@ -772,7 +773,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView):
|
|||
)
|
||||
vm = manager.get_vm(obj.vm_id)
|
||||
context['vm'] = VirtualMachineSerializer(vm).data
|
||||
price, vat, vat_percent = get_vm_price_with_vat(
|
||||
price, vat, vat_percent, discount = get_vm_price_with_vat(
|
||||
cpu=context['vm']['cores'],
|
||||
ssd_size=context['vm']['disk_size'],
|
||||
memory=context['vm']['memory'],
|
||||
|
@ -781,8 +782,9 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView):
|
|||
)
|
||||
context['vm']['vat'] = vat
|
||||
context['vm']['price'] = price
|
||||
context['vm']['discount'] = discount
|
||||
context['vm']['vat_percent'] = vat_percent
|
||||
context['vm']['total_price'] = price + vat
|
||||
context['vm']['total_price'] = price + vat - discount
|
||||
except WrongIdError:
|
||||
messages.error(
|
||||
self.request,
|
||||
|
@ -809,9 +811,6 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView):
|
|||
context['cc_brand'] = card_details.get('response_object').get(
|
||||
'cc_brand')
|
||||
context['vm'] = self.request.session.get('specs')
|
||||
context['vm_pricing'] = VMPricing.get_vm_pricing_by_name(
|
||||
self.request.session['specs']['pricing_name']
|
||||
),
|
||||
return context
|
||||
|
||||
@method_decorator(decorators)
|
||||
|
@ -1071,7 +1070,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
|
|||
extra_tags='storage')
|
||||
return redirect(CreateVirtualMachinesView.as_view())
|
||||
|
||||
price, vat, vat_percent = get_vm_price_with_vat(
|
||||
price, vat, vat_percent, discount = get_vm_price_with_vat(
|
||||
cpu=cores,
|
||||
memory=memory,
|
||||
ssd_size=storage,
|
||||
|
@ -1085,7 +1084,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
|
|||
'price': price,
|
||||
'vat': vat,
|
||||
'vat_percent': vat_percent,
|
||||
'total_price': price + vat,
|
||||
'total_price': price + vat - discount,
|
||||
'pricing_name': vm_pricing_name
|
||||
}
|
||||
|
||||
|
|
|
@ -111,8 +111,7 @@ def get_vm_price_with_vat(cpu, memory, ssd_size, hdd_size=0,
|
|||
(decimal.Decimal(cpu) * pricing.cores_unit_price) +
|
||||
(decimal.Decimal(memory) * pricing.ram_unit_price) +
|
||||
(decimal.Decimal(ssd_size) * pricing.ssd_unit_price) +
|
||||
(decimal.Decimal(hdd_size) * pricing.hdd_unit_price) -
|
||||
pricing.discount_amount
|
||||
(decimal.Decimal(hdd_size) * pricing.hdd_unit_price)
|
||||
)
|
||||
if pricing.vat_inclusive:
|
||||
vat = decimal.Decimal(0)
|
||||
|
@ -124,4 +123,5 @@ 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)
|
||||
return float(price), float(vat), float(vat_percent)
|
||||
discount = pricing.discount_amount
|
||||
return float(price), float(vat), float(vat_percent), float(discount)
|
||||
|
|
Loading…
Reference in a new issue