+
{%trans "Total" %} {%trans "including VAT" %}
-
{{request.session.specs.price|intcomma}}
- CHF
/{% trans "Month" %}
+
+ {{request.session.specs.price|intcomma}} CHF/{% trans "Month" %}
diff --git a/hosting/views.py b/hosting/views.py
index b288be3b..63d99a91 100644
--- a/hosting/views.py
+++ b/hosting/views.py
@@ -30,7 +30,7 @@ from stored_messages.api import mark_read
from stored_messages.models import Message
from stored_messages.settings import stored_messages_settings
-from datacenterlight.models import VMTemplate
+from datacenterlight.models import VMTemplate, VMPricing
from datacenterlight.tasks import create_vm_task
from datacenterlight.utils import get_cms_integration
from membership.models import CustomUser, StripeCustomer
@@ -1020,18 +1020,34 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
storage = request.POST.get('storage')
storage_field = forms.IntegerField(validators=[self.validate_storage])
template_id = int(request.POST.get('config'))
+ pricing_name = request.POST.get('pricing_name')
+ vm_pricing = VMPricing.get_vm_pricing_by_name(pricing_name)
template = VMTemplate.objects.filter(
opennebula_vm_template_id=template_id).first()
template_data = VMTemplateSerializer(template).data
+ if vm_pricing is None:
+ vm_pricing_name_msg = _(
+ "Incorrect pricing name. Please contact support"
+ "{support_email}".format(
+ support_email=settings.DCL_SUPPORT_FROM_ADDRESS
+ )
+ )
+ messages.add_message(
+ self.request, messages.ERROR, vm_pricing_name_msg,
+ extra_tags='pricing'
+ )
+ return redirect(CreateVirtualMachinesView.as_view())
+ else:
+ vm_pricing_name = vm_pricing.name
+
try:
cores = cores_field.clean(cores)
except ValidationError as err:
msg = '{} : {}.'.format(cores, str(err))
messages.add_message(self.request, messages.ERROR, msg,
extra_tags='cores')
- return HttpResponseRedirect(
- reverse('datacenterlight:index') + "#order_form")
+ return redirect(CreateVirtualMachinesView.as_view())
try:
memory = memory_field.clean(memory)
@@ -1039,8 +1055,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
msg = '{} : {}.'.format(memory, str(err))
messages.add_message(self.request, messages.ERROR, msg,
extra_tags='memory')
- return HttpResponseRedirect(
- reverse('datacenterlight:index') + "#order_form")
+ return redirect(CreateVirtualMachinesView.as_view())
try:
storage = storage_field.clean(storage)
@@ -1048,15 +1063,24 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
msg = '{} : {}.'.format(storage, str(err))
messages.add_message(self.request, messages.ERROR, msg,
extra_tags='storage')
- return HttpResponseRedirect(
- reverse('datacenterlight:index') + "#order_form")
- price = get_vm_price(cpu=cores, memory=memory,
- disk_size=storage)
+ return redirect(CreateVirtualMachinesView.as_view())
+
+ price, vat, vat_percent = get_vm_price_with_vat(
+ cpu=cores,
+ memory=memory,
+ ssd_size=storage,
+ pricing_name=vm_pricing_name
+ )
+
specs = {
'cpu': cores,
'memory': memory,
'disk_size': storage,
- 'price': price
+ 'price': price,
+ 'vat': vat,
+ 'vat_percent': vat_percent,
+ 'total_price': price + vat,
+ 'pricing_name': vm_pricing_name
}
request.session['specs'] = specs