From fd4f61bc5c5fa4af97fe9477e250039e074b20c4 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 10 Jan 2020 20:16:16 +0530 Subject: [PATCH 001/283] Update Changelog for 2.9.4 --- Changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog b/Changelog index 1cd2eb05..5c3b0551 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +2.9.4: 2020-01-10 + * Bugfix: Buying VPN generic item caused 500 error 2.9.3: 2020-01-05 * Feature: Add StripeTaxRate model to save tax rates created in Stripe * Bugfix: Add vat rates for CY, IL and LI manually From a00a9f6ff054f0e6f31070cdf9b5ff54e4f342e1 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 20 Jan 2020 12:07:32 +0530 Subject: [PATCH 002/283] Show invoices directly from stripe --- datacenterlight/templatetags/custom_tags.py | 62 ++++++++++++++- hosting/templates/hosting/dashboard.html | 2 +- hosting/templates/hosting/invoices.html | 60 ++++++++------- hosting/views.py | 83 ++++++++------------- utils/hosting_utils.py | 9 +++ 5 files changed, 139 insertions(+), 77 deletions(-) diff --git a/datacenterlight/templatetags/custom_tags.py b/datacenterlight/templatetags/custom_tags.py index a2b20bcb..4cc50caa 100644 --- a/datacenterlight/templatetags/custom_tags.py +++ b/datacenterlight/templatetags/custom_tags.py @@ -1,6 +1,11 @@ +import datetime + from django import template from django.core.urlresolvers import resolve, reverse -from django.utils.translation import activate, get_language +from django.utils.safestring import mark_safe +from django.utils.translation import activate, get_language, ugettext_lazy as _ + +from utils.hosting_utils import get_ip_addresses register = template.Library() @@ -52,3 +57,58 @@ def escaped_line_break(value): :return: """ return value.replace("\\n", "\n") + + +@register.filter('get_line_item_from_stripe_invoice') +def get_line_item_from_stripe_invoice(invoice): + """ + Returns ready-to-use "html" line item to be shown for an invoice in the + invoice list page + + :param invoice: the stripe Invoice object + :return: + """ + start_date = 0 + end_date = 0 + is_first = True + vm_id = -1 + for line_data in invoice["lines"]["data"]: + if is_first: + start_date = line_data.period.start + end_date = line_data.period.end + is_first = False + if hasattr(line_data.metadata, "VM_ID"): + vm_id = line_data.metadata.VM_ID + else: + if line_data.period.start < start_date: + start_date = line_data.period.start + if line_data.period.end > end_date: + end_date = line_data.period.end + if hasattr(line_data.metadata, "VM_ID"): + vm_id = line_data.metadata.VM_ID + + try: + vm_id = int(vm_id) + except ValueError as ve: + print(str(ve)) + if invoice["lines"]["data"]: + return mark_safe(""" + {vm_id} + {ip_addresses} + {period} + {total} + + {see_invoice_text} + + """.format( + vm_id=vm_id if vm_id > 0 else "", + ip_addresses=mark_safe(get_ip_addresses(vm_id)) if vm_id > 0 else "", + period = mark_safe("%s — %s" % ( + datetime.datetime.fromtimestamp(start_date).strftime('%Y-%m-%d'), + datetime.datetime.fromtimestamp(end_date).strftime('%Y-%m-%d'))), + total=invoice.total/100, + stripe_invoice_url=invoice.hosted_invoice_url, + see_invoice_text=_("See Invoice") + )) + else: + return "" diff --git a/hosting/templates/hosting/dashboard.html b/hosting/templates/hosting/dashboard.html index bda6eb11..212c5885 100644 --- a/hosting/templates/hosting/dashboard.html +++ b/hosting/templates/hosting/dashboard.html @@ -29,7 +29,7 @@ - +

{% trans "My Bills" %}

diff --git a/hosting/templates/hosting/invoices.html b/hosting/templates/hosting/invoices.html index 5f7be4b4..f48802d1 100644 --- a/hosting/templates/hosting/invoices.html +++ b/hosting/templates/hosting/invoices.html @@ -26,36 +26,46 @@ - {% for invoice in invoices %} + {% for inv_data in invs %} - {{ invoice.order.vm_id }} - {{ ips|get_value_from_dict:invoice.invoice_number|join:"
" }} - {% with period|get_value_from_dict:invoice.invoice_number as period_to_show %} - {{ period_to_show.period_start | date:'Y-m-d' }} — {{ period_to_show.period_end | date:'Y-m-d' }} - {% endwith %} - {{ invoice.total_in_chf|floatformat:2|intcomma }} - -
{% trans 'See Invoice' %} - + {{ inv_data | get_line_item_from_stripe_invoice }} {% endfor %} - - {% if is_paginated %} - +{% if invs.has_other_pages %} +
    + {% if invs.has_previous %} + {% if user_email %} +
  • «
  • + {% else %} +
  • «
  • + {% endif %} + {% else %} +
  • «
  • {% endif %} + {% for i in invs.paginator.page_range %} + {% if invs.number == i %} +
  • {{ i }} (current)
  • + {% else %} + {% if user_email %} +
  • {{ i }}
  • + {% else %} +
  • {{ i }}
  • + {% endif %} + {% endif %} + {% endfor %} + {% if invs.has_next %} + {% if user_email %} +
  • »
  • + {% else %} +
  • »
  • + {% endif %} + {% else %} +
  • »
  • + {% endif %} +
+{% endif %} +
{% endblock %} diff --git a/hosting/views.py b/hosting/views.py index bd72af94..c5d505bf 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -3,6 +3,7 @@ import uuid from datetime import datetime from time import sleep +import stripe from django import forms from django.conf import settings from django.contrib import messages @@ -10,6 +11,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.tokens import default_token_generator from django.core.exceptions import ValidationError from django.core.files.base import ContentFile +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.urlresolvers import reverse_lazy, reverse from django.http import ( Http404, HttpResponseRedirect, HttpResponse, JsonResponse @@ -40,7 +42,6 @@ from datacenterlight.models import VMTemplate, VMPricing from datacenterlight.utils import ( create_vm, get_cms_integration, check_otp, validate_vat_number ) -from dynamicweb.settings.base import DCL_ERROR_EMAILS_TO_LIST from hosting.models import UserCardDetail from membership.models import CustomUser, StripeCustomer from opennebula_api.models import OpenNebulaManager @@ -57,11 +58,10 @@ from utils.hosting_utils import ( get_vm_price_with_vat, get_vm_price_for_given_vat, HostingUtils, get_vat_rate_for_country ) +from utils.ldap_manager import LdapManager from utils.mailer import BaseEmail from utils.stripe_utils import StripeUtils from utils.tasks import send_plain_email_task -from utils.ldap_manager import LdapManager - from utils.views import ( PasswordResetViewMixin, PasswordResetConfirmViewMixin, LoginViewMixin, ResendActivationLinkViewMixin @@ -73,7 +73,7 @@ from .forms import ( from .mixins import ProcessVMSelectionMixin, HostingContextMixin from .models import ( HostingOrder, HostingBill, HostingPlan, UserHostingKey, VMDetail, - GenericProduct, MonthlyHostingBill, HostingBillLineItem + GenericProduct, MonthlyHostingBill ) logger = logging.getLogger(__name__) @@ -1240,7 +1240,7 @@ class OrdersHostingListView(LoginRequiredMixin, ListView): return super(OrdersHostingListView, self).get(request, *args, **kwargs) -class InvoiceListView(LoginRequiredMixin, ListView): +class InvoiceListView(LoginRequiredMixin, TemplateView): template_name = "hosting/invoices.html" login_url = reverse_lazy('hosting:login') context_object_name = "invoices" @@ -1248,10 +1248,13 @@ class InvoiceListView(LoginRequiredMixin, ListView): ordering = '-created' def get_context_data(self, **kwargs): + page = self.request.GET.get('page', 1) context = super(InvoiceListView, self).get_context_data(**kwargs) + invs_page = None if ('user_email' in self.request.GET and self.request.user.email == settings.ADMIN_EMAIL): user_email = self.request.GET['user_email'] + context['user_email'] = user_email logger.debug( "user_email = {}".format(user_email) ) @@ -1260,54 +1263,34 @@ class InvoiceListView(LoginRequiredMixin, ListView): except CustomUser.DoesNotExist as dne: logger.debug("User does not exist") cu = self.request.user - mhbs = MonthlyHostingBill.objects.filter(customer__user=cu) - else: - mhbs = MonthlyHostingBill.objects.filter( - customer__user=self.request.user - ) - ips_dict = {} - line_item_period_dict = {} - for mhb in mhbs: + invs = stripe.Invoice.list(customer=cu.stripecustomer.stripe_id, + count=100) + paginator = Paginator(invs.data, 10) try: - vm_detail = VMDetail.objects.get(vm_id=mhb.order.vm_id) - ips_dict[mhb.invoice_number] = [vm_detail.ipv6, vm_detail.ipv4] - all_line_items = HostingBillLineItem.objects.filter(monthly_hosting_bill=mhb) - for line_item in all_line_items: - if line_item.get_item_detail_str() != "": - line_item_period_dict[mhb.invoice_number] = { - "period_start": line_item.period_start, - "period_end": line_item.period_end - } - break - except VMDetail.DoesNotExist as dne: - ips_dict[mhb.invoice_number] = ['--'] - logger.debug("VMDetail for {} doesn't exist".format( - mhb.order.vm_id - )) - context['ips'] = ips_dict - context['period'] = line_item_period_dict + invs_page = paginator.page(page) + except PageNotAnInteger: + invs_page = paginator.page(1) + except EmptyPage: + invs_page = paginator.page(paginator.num_pages) + else: + try: + invs = stripe.Invoice.list( + customer=self.request.user.stripecustomer.stripe_id, + count=100 + ) + paginator = Paginator(invs.data, 10) + try: + invs_page = paginator.page(page) + except PageNotAnInteger: + invs_page = paginator.page(1) + except EmptyPage: + invs_page = paginator.page(paginator.num_pages) + except Exception as ex: + logger.error(str(ex)) + invs_page = None + context["invs"] = invs_page return context - def get_queryset(self): - user = self.request.user - if ('user_email' in self.request.GET - and self.request.user.email == settings.ADMIN_EMAIL): - user_email = self.request.GET['user_email'] - logger.debug( - "user_email = {}".format(user_email) - ) - try: - cu = CustomUser.objects.get(email=user_email) - except CustomUser.DoesNotExist as dne: - logger.debug("User does not exist") - cu = self.request.user - self.queryset = MonthlyHostingBill.objects.filter(customer__user=cu) - else: - self.queryset = MonthlyHostingBill.objects.filter( - customer__user=self.request.user - ) - return super(InvoiceListView, self).get_queryset() - @method_decorator(decorators) def get(self, request, *args, **kwargs): return super(InvoiceListView, self).get(request, *args, **kwargs) diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 73e2c035..3674185c 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -199,6 +199,15 @@ def get_vat_rate_for_country(country): return 0 +def get_ip_addresses(vm_id): + try: + vm_detail = VMDetail.objects.get(vm_id=vm_id) + return "%s
%s" % (vm_detail.ipv6, vm_detail.ipv4) + except VMDetail.DoesNotExist as dne: + logger.error(str(dne)) + logger.error("VMDetail for %s does not exist" % vm_id) + return "--" + class HostingUtils: @staticmethod def clear_items_from_list(from_list, items_list): From 0b2a305f57ece9368eabfdc036ca0a438e68f280 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 20 Jan 2020 12:09:49 +0530 Subject: [PATCH 003/283] Fix pep warning --- utils/hosting_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 3674185c..f47905a5 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -208,6 +208,7 @@ def get_ip_addresses(vm_id): logger.error("VMDetail for %s does not exist" % vm_id) return "--" + class HostingUtils: @staticmethod def clear_items_from_list(from_list, items_list): From a82c4d556c75097c1d1da1017660acff0d47a208 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 20 Jan 2020 13:25:49 +0530 Subject: [PATCH 004/283] Update Changelog for 2.9.5 --- Changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog b/Changelog index 5c3b0551..566f5960 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +2.9.5: 2020-01-20 + * Feature: Show invoices directly from stripe (MR!727) 2.9.4: 2020-01-10 * Bugfix: Buying VPN generic item caused 500 error 2.9.3: 2020-01-05 From 399f9ed6c9c34b93f2af7feb44dbc995b448dec9 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 23 Jan 2020 16:37:35 +0530 Subject: [PATCH 005/283] Adjust hosting VM buy flow --- hosting/views.py | 38 ++++++++++++++++++++++++++++++++++---- utils/stripe_utils.py | 32 ++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index c5d505bf..43b6f5a7 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -42,7 +42,7 @@ from datacenterlight.models import VMTemplate, VMPricing from datacenterlight.utils import ( create_vm, get_cms_integration, check_otp, validate_vat_number ) -from hosting.models import UserCardDetail +from hosting.models import UserCardDetail, StripeTaxRate from membership.models import CustomUser, StripeCustomer from opennebula_api.models import OpenNebulaManager from opennebula_api.serializers import ( @@ -1135,7 +1135,8 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView, FormView): cpu = specs.get('cpu') memory = specs.get('memory') disk_size = specs.get('disk_size') - amount_to_be_charged = specs.get('total_price') + amount_to_be_charged = specs.get('price') + discount = specs.get('discount') plan_name = StripeUtils.get_stripe_plan_name( cpu=cpu, memory=memory, @@ -1154,10 +1155,39 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView, FormView): amount=amount_to_be_charged, name=plan_name, stripe_plan_id=stripe_plan_id) + # Create StripeTaxRate if applicable to the user + stripe_tax_rate = None + if specs["vat_percent"] > 0: + try: + stripe_tax_rate = StripeTaxRate.objects.get( + description="VAT for %s" % specs["vat_country"] + ) + print("Stripe Tax Rate exists") + except StripeTaxRate.DoesNotExist as dne: + print("StripeTaxRate does not exist") + tax_rate_obj = stripe.TaxRate.create( + display_name="VAT", + description="VAT for %s" % specs["vat_country"], + jurisdiction=specs["vat_country"], + percentage=specs["vat_percent"] * 100, + inclusive=False, + ) + stripe_tax_rate = StripeTaxRate.objects.create( + display_name=tax_rate_obj.display_name, + description=tax_rate_obj.description, + jurisdiction=tax_rate_obj.jurisdiction, + percentage=tax_rate_obj.percentage, + inclusive=False, + tax_rate_id=tax_rate_obj.id + ) + logger.debug("Created StripeTaxRate %s" % + stripe_tax_rate.tax_rate_id) subscription_result = stripe_utils.subscribe_customer_to_plan( stripe_api_cus_id, - [{"plan": stripe_plan.get( - 'response_object').stripe_plan_id}]) + [{"plan": stripe_plan.get('response_object').stripe_plan_id}], + coupon='ipv6-discount-8chf' if 'name' in discount and 'ipv6' in discount['name'].lower() else "", + tax_rate=[stripe_tax_rate.tax_rate_id] if stripe_tax_rate else [], + ) stripe_subscription_obj = subscription_result.get('response_object') # Check if the subscription was approved and is active if (stripe_subscription_obj is None or diff --git a/utils/stripe_utils.py b/utils/stripe_utils.py index de16fe4b..45904f14 100644 --- a/utils/stripe_utils.py +++ b/utils/stripe_utils.py @@ -297,7 +297,8 @@ class StripeUtils(object): return return_value @handleStripeError - def subscribe_customer_to_plan(self, customer, plans, trial_end=None): + def subscribe_customer_to_plan(self, customer, plans, trial_end=None, + coupon="", tax_rates=list()): """ Subscribes the given customer to the list of given plans @@ -316,7 +317,9 @@ class StripeUtils(object): """ subscription_result = self.stripe.Subscription.create( - customer=customer, items=plans, trial_end=trial_end + customer=customer, items=plans, trial_end=trial_end, + coupon=coupon, + default_tax_rates=tax_rates, ) return subscription_result @@ -410,18 +413,27 @@ class StripeUtils(object): @staticmethod - def get_stripe_plan_name(cpu, memory, disk_size, price): + def get_stripe_plan_name(cpu, memory, disk_size, price, excl_vat=True): """ Returns the Stripe plan name :return: """ - return "{cpu} Cores, {memory} GB RAM, {disk_size} GB SSD, " \ - "{price} CHF".format( - cpu=cpu, - memory=memory, - disk_size=disk_size, - price=round(price, 2) - ) + if excl_vat: + return "{cpu} Cores, {memory} GB RAM, {disk_size} GB SSD, " \ + "{price} CHF Excl. VAT".format( + cpu=cpu, + memory=memory, + disk_size=disk_size, + price=round(price, 2) + ) + else: + return "{cpu} Cores, {memory} GB RAM, {disk_size} GB SSD, " \ + "{price} CHF".format( + cpu=cpu, + memory=memory, + disk_size=disk_size, + price=round(price, 2) + ) @handleStripeError def set_subscription_meta_data(self, subscription_id, meta_data): From ec00785068dc38f9b946cc0e1f371b3f298a96b5 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 24 Jan 2020 14:10:56 +0530 Subject: [PATCH 006/283] Update get_stripe_plan_id to make it compatible with excl_vat --- utils/stripe_utils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/utils/stripe_utils.py b/utils/stripe_utils.py index 45904f14..ade06dd3 100644 --- a/utils/stripe_utils.py +++ b/utils/stripe_utils.py @@ -1,7 +1,9 @@ import logging import re + import stripe from django.conf import settings + from datacenterlight.models import StripePlan stripe.api_key = settings.STRIPE_API_PRIVATE_KEY @@ -351,7 +353,7 @@ class StripeUtils(object): @staticmethod def get_stripe_plan_id(cpu, ram, ssd, version, app='dcl', hdd=None, - price=None): + price=None, excl_vat=True): """ Returns the Stripe plan id string of the form `dcl-v1-cpu-2-ram-5gb-ssd-10gb` based on the input parameters @@ -378,13 +380,16 @@ class StripeUtils(object): plan=dcl_plan_string ) if price is not None: - stripe_plan_id_string_with_price = '{}-{}chf'.format( + stripe_plan_id_string = '{}-{}chf'.format( stripe_plan_id_string, round(price, 2) ) - return stripe_plan_id_string_with_price - else: - return stripe_plan_id_string + if excl_vat: + stripe_plan_id_string = '{}-{}'.format( + stripe_plan_id_string, + "excl_vat" + ) + return stripe_plan_id_string @staticmethod def get_vm_config_from_stripe_id(stripe_id): From e01b27835ea64f2001834fde56c46ba8726d065d Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 24 Jan 2020 14:11:55 +0530 Subject: [PATCH 007/283] Make subscription exclusive of VAT + Add VAT separately to subscription --- datacenterlight/views.py | 58 +++++++++++++++++++++++++++++++++++----- hosting/views.py | 2 +- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index d2581fd9..92c65681 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -1,5 +1,6 @@ import logging +import stripe from django import forms from django.conf import settings from django.contrib import messages @@ -17,8 +18,8 @@ from hosting.forms import ( UserHostingKeyForm ) from hosting.models import ( - HostingBill, HostingOrder, UserCardDetail, GenericProduct, UserHostingKey -) + HostingBill, HostingOrder, UserCardDetail, GenericProduct, UserHostingKey, + StripeTaxRate) from membership.models import CustomUser, StripeCustomer from opennebula_api.models import OpenNebulaManager from opennebula_api.serializers import VMTemplateSerializer @@ -840,9 +841,15 @@ class OrderConfirmationView(DetailView, FormView): (request.session['generic_payment_details']['recurring'])): recurring_interval = 'month' if 'generic_payment_details' in request.session: + vat_percent = request.session['generic_payment_details']['vat_rate'] + vat_country = request.session['generic_payment_details']['vat_country'] + if 'discount' in request.session['generic_payment_details']: + discount = request.session['generic_payment_details']['discount'] + else: + discount = {'name': '', 'amount': 0, 'coupon_id': ''} amount_to_be_charged = ( round( - request.session['generic_payment_details']['amount'], + request.session['generic_payment_details']['amount_before_vat'], 2 ) ) @@ -863,7 +870,10 @@ class OrderConfirmationView(DetailView, FormView): cpu = specs.get('cpu') memory = specs.get('memory') disk_size = specs.get('disk_size') - amount_to_be_charged = specs.get('total_price') + amount_to_be_charged = specs.get('price') + vat_percent = specs.get('vat_percent') + vat_country = specs.get('vat_country') + discount = specs.get('discount') plan_name = StripeUtils.get_stripe_plan_name( cpu=cpu, memory=memory, @@ -884,10 +894,46 @@ class OrderConfirmationView(DetailView, FormView): stripe_plan_id=stripe_plan_id, interval=recurring_interval ) + # Create StripeTaxRate if applicable to the user + logger.debug("vat_percent = %s, vat_country = %s" % + (vat_percent, vat_country) + ) + stripe_tax_rate = None + if vat_percent > 0: + try: + stripe_tax_rate = StripeTaxRate.objects.get( + description="VAT for %s" % vat_country + ) + print("Stripe Tax Rate exists") + except StripeTaxRate.DoesNotExist as dne: + print("StripeTaxRate does not exist") + tax_rate_obj = stripe.TaxRate.create( + display_name="VAT", + description="VAT for %s" % vat_country, + jurisdiction=vat_country, + percentage=vat_percent, + inclusive=False, + ) + stripe_tax_rate = StripeTaxRate.objects.create( + display_name=tax_rate_obj.display_name, + description=tax_rate_obj.description, + jurisdiction=tax_rate_obj.jurisdiction, + percentage=tax_rate_obj.percentage, + inclusive=False, + tax_rate_id=tax_rate_obj.id + ) + logger.debug("Created StripeTaxRate %s" % + stripe_tax_rate.tax_rate_id) subscription_result = stripe_utils.subscribe_customer_to_plan( stripe_api_cus_id, - [{"plan": stripe_plan.get( - 'response_object').stripe_plan_id}]) + [{"plan": stripe_plan.get('response_object').stripe_plan_id}], + coupon='ipv6-discount-8chf' if ( + 'name' in discount and + discount['name'] is not None and + 'ipv6' in discount['name'].lower() + ) else "", + tax_rates=[stripe_tax_rate.tax_rate_id] if stripe_tax_rate else [], + ) stripe_subscription_obj = subscription_result.get('response_object') # Check if the subscription was approved and is active if (stripe_subscription_obj is None diff --git a/hosting/views.py b/hosting/views.py index 43b6f5a7..672868d8 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1186,7 +1186,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView, FormView): stripe_api_cus_id, [{"plan": stripe_plan.get('response_object').stripe_plan_id}], coupon='ipv6-discount-8chf' if 'name' in discount and 'ipv6' in discount['name'].lower() else "", - tax_rate=[stripe_tax_rate.tax_rate_id] if stripe_tax_rate else [], + tax_rates=[stripe_tax_rate.tax_rate_id] if stripe_tax_rate else [], ) stripe_subscription_obj = subscription_result.get('response_object') # Check if the subscription was approved and is active From 38550ea75c5de1b3de12a6979813793a1900bedb Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 24 Jan 2020 15:00:16 +0530 Subject: [PATCH 008/283] Rearrange the way we show VAT and discount calculations --- .../datacenterlight/order_detail.html | 20 +++++++++++-------- utils/hosting_utils.py | 8 +++++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index db3f73a8..80e35914 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -126,21 +126,25 @@
{% if vm.vat > 0 %}

- {% trans "Subtotal" %} + {% trans "Price" %} {{vm.price|floatformat:2|intcomma}} CHF

+ {% if vm.discount.amount > 0 %} +

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

+ {% endif %} +

+ {% trans "Subtotal" %} + {{vm.price - vm.discount.amount|floatformat:2|intcomma}} CHF +

{% trans "VAT for" %} {{vm.vat_country}} ({{vm.vat_percent}}%) : {{vm.vat|floatformat:2|intcomma}} CHF

{% endif %} - {% if vm.discount.amount > 0 %} -

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

- {% endif %}
diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index f47905a5..2705143c 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -104,15 +104,17 @@ def get_vm_price_for_given_vat(cpu, memory, ssd_size, hdd_size=0, (decimal.Decimal(hdd_size) * pricing.hdd_unit_price) ) - vat = price * decimal.Decimal(vat_rate) * decimal.Decimal(0.01) + discount_name = pricing.discount_name + discount_amount = round(float(pricing.discount_amount), 2) + vat = (price - discount_amount) * decimal.Decimal(vat_rate) * decimal.Decimal(0.01) vat_percent = vat_rate cents = decimal.Decimal('.01') price = price.quantize(cents, decimal.ROUND_HALF_UP) vat = vat.quantize(cents, decimal.ROUND_HALF_UP) discount = { - 'name': pricing.discount_name, - 'amount': round(float(pricing.discount_amount), 2) + 'name': discount_name, + 'amount': discount_amount } return (round(float(price), 2), round(float(vat), 2), round(float(vat_percent), 2), discount) From 112f3e17a9ce7d2f998546e7690261c2a000225b Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 24 Jan 2020 15:03:07 +0530 Subject: [PATCH 009/283] Convert to decimal for type consistency --- utils/hosting_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 2705143c..3312474d 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -106,7 +106,7 @@ def get_vm_price_for_given_vat(cpu, memory, ssd_size, hdd_size=0, discount_name = pricing.discount_name discount_amount = round(float(pricing.discount_amount), 2) - vat = (price - discount_amount) * decimal.Decimal(vat_rate) * decimal.Decimal(0.01) + vat = (price - decimal.Decimal(discount_amount)) * decimal.Decimal(vat_rate) * decimal.Decimal(0.01) vat_percent = vat_rate cents = decimal.Decimal('.01') From 156930ab26418f260967cf5cf60f250cb27f81ba Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 24 Jan 2020 15:24:46 +0530 Subject: [PATCH 010/283] Add price_after_discount explicitly for showing in template --- datacenterlight/templates/datacenterlight/order_detail.html | 2 +- datacenterlight/views.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 80e35914..c2b97556 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -138,7 +138,7 @@ {% endif %}

{% trans "Subtotal" %} - {{vm.price - vm.discount.amount|floatformat:2|intcomma}} CHF + {{vm.price_after_discount}} CHF

{% trans "VAT for" %} {{vm.vat_country}} ({{vm.vat_percent}}%) : diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 92c65681..8c1fe504 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -642,6 +642,7 @@ class OrderConfirmationView(DetailView, FormView): vat_rate=user_country_vat_rate * 100 ) vm_specs["price"] = price + vm_specs["price_after_discount"] = price - discount vat_number = request.session.get('billing_address_data').get("vat_number") billing_address = BillingAddress.objects.get(id=request.session["billing_address_id"]) From d1fd57b7308b60ab8e82ba56bfcd44823ce0d724 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 24 Jan 2020 15:26:41 +0530 Subject: [PATCH 011/283] Correct the way we get amount from discount --- datacenterlight/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 8c1fe504..b2dec576 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -642,7 +642,7 @@ class OrderConfirmationView(DetailView, FormView): vat_rate=user_country_vat_rate * 100 ) vm_specs["price"] = price - vm_specs["price_after_discount"] = price - discount + vm_specs["price_after_discount"] = price - discount["amount"] vat_number = request.session.get('billing_address_data').get("vat_number") billing_address = BillingAddress.objects.get(id=request.session["billing_address_id"]) From cde6c51d4b22a3b8ada0a4362c8d17daff0847d7 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 26 Jan 2020 10:06:31 +0530 Subject: [PATCH 012/283] Reset vat_validation_status when on payment page --- datacenterlight/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index b2dec576..0d62cf1e 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -309,6 +309,7 @@ class PaymentOrderView(FormView): @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): + request.session.pop('vat_validation_status') if (('type' in request.GET and request.GET['type'] == 'generic') or 'product_slug' in kwargs): request.session['generic_payment_type'] = 'generic' From 24740438f7f05eff23561454928a3eb06faa3044 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 29 Jan 2020 16:02:26 +0530 Subject: [PATCH 013/283] get_vm_price_for_given_vat: Also return discount amount with vat --- utils/hosting_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 3312474d..61f849ad 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -114,7 +114,8 @@ def get_vm_price_for_given_vat(cpu, memory, ssd_size, hdd_size=0, vat = vat.quantize(cents, decimal.ROUND_HALF_UP) discount = { 'name': discount_name, - 'amount': discount_amount + 'amount': discount_amount, + 'amount_with_vat': round(discount_amount * vat_rate, 2) } return (round(float(price), 2), round(float(vat), 2), round(float(vat_percent), 2), discount) From 970834cc38e77a2d3e3a1c9275e5cb677a157fc3 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 29 Jan 2020 16:03:13 +0530 Subject: [PATCH 014/283] Add parameters needed for displaying prices after discount, and vat --- datacenterlight/views.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 0d62cf1e..f1911cbf 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -681,6 +681,9 @@ class OrderConfirmationView(DetailView, FormView): 2) vm_specs["vat_country"] = user_vat_country vm_specs["discount"] = discount + vm_specs["price_with_vat"] = price + vat + vm_specs["price_after_discount"] = round(price - discount['amount'], 2) + vm_specs["price_after_discount_with_vat"] = round((price - discount['amount']) + vm_specs["vat"], 2) request.session['specs'] = vm_specs context.update({ From b8eca59e0dbfdae39daf2b6f0420735eda832116 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 29 Jan 2020 16:04:03 +0530 Subject: [PATCH 015/283] Fix design for showing prices excl and incl vat and discount --- .../datacenterlight/order_detail.html | 127 +++++++++++++----- 1 file changed, 94 insertions(+), 33 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index c2b97556..f62fd063 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -121,40 +121,101 @@


- {% if vm.vat > 0 or vm.discount.amount > 0 %} -
-
- {% if vm.vat > 0 %} -

- {% trans "Price" %} - {{vm.price|floatformat:2|intcomma}} CHF -

- {% if vm.discount.amount > 0 %} -

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

- {% endif %} -

- {% trans "Subtotal" %} - {{vm.price_after_discount}} CHF -

-

- {% trans "VAT for" %} {{vm.vat_country}} ({{vm.vat_percent}}%) : - {{vm.vat|floatformat:2|intcomma}} CHF -

- {% endif %} -
-
-
-
-
- {% endif %}
-

- {% trans "Total" %} - {{vm.total_price|floatformat:2|intcomma}} CHF +

+ {% trans "Price Before VAT" %} + {{vm.price|intcomma}} CHF +

+
+
+
+
+
+ +
+
+

+
+
+

Pre VAT

+
+
+

VAT for {{vm.vat_country}} ({{vm.vat_percent}}%)

+
+
+
+
+

Price

+
+
+

{{vm.price|intcomma}} CHF

+
+
+

{{vm.price_with_vat|intcomma}} CHF

+
+
+ {% if vm.discount.amount > 0 %} +
+
+

{{vm.discount.name}}

+
+
+

-{{vm.discount.amount|intcomma}} CHF

+
+
+

-{{vm.discount.amount_with_vat|intcomma}} CHF

+
+
+ {% endif %} +
+
+
+
+
+
+
+

Total

+
+
+

{{vm.price_after_discount|intcomma}} CHF

+
+
+

{{vm.price_after_discount_with_vat|intcomma}} CHF

+
+
+
+
+
+
+
+

+ {% trans "Your Price in Total" %} + {{vm.total_price|floatformat:2|intcomma}} CHF

From 1f79ccd490ac9734d7f40508ec88da2effb545a9 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 29 Jan 2020 16:15:28 +0530 Subject: [PATCH 016/283] Convert discount amount into CHF --- utils/hosting_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 61f849ad..85829d05 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -115,7 +115,7 @@ def get_vm_price_for_given_vat(cpu, memory, ssd_size, hdd_size=0, discount = { 'name': discount_name, 'amount': discount_amount, - 'amount_with_vat': round(discount_amount * vat_rate, 2) + 'amount_with_vat': round(discount_amount * vat_rate * 0.01, 2) } return (round(float(price), 2), round(float(vat), 2), round(float(vat_percent), 2), discount) From 48cc2b49394c97433ed2d435490b38edc908b1f2 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 29 Jan 2020 16:19:48 +0530 Subject: [PATCH 017/283] Fix discount amount calculation after VAT --- utils/hosting_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 85829d05..e20e9b16 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -115,7 +115,7 @@ def get_vm_price_for_given_vat(cpu, memory, ssd_size, hdd_size=0, discount = { 'name': discount_name, 'amount': discount_amount, - 'amount_with_vat': round(discount_amount * vat_rate * 0.01, 2) + 'amount_with_vat': round(discount_amount * (1 + vat_rate * 0.01), 2) } return (round(float(price), 2), round(float(vat), 2), round(float(vat_percent), 2), discount) From 6132638faa2e438196ce12f20a6f2fbdfa563da2 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 29 Jan 2020 16:32:07 +0530 Subject: [PATCH 018/283] Use correct vat --- datacenterlight/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index f1911cbf..f8f7f928 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -681,7 +681,7 @@ class OrderConfirmationView(DetailView, FormView): 2) vm_specs["vat_country"] = user_vat_country vm_specs["discount"] = discount - vm_specs["price_with_vat"] = price + vat + vm_specs["price_with_vat"] = price + vm_specs["vat"] vm_specs["price_after_discount"] = round(price - discount['amount'], 2) vm_specs["price_after_discount_with_vat"] = round((price - discount['amount']) + vm_specs["vat"], 2) request.session['specs'] = vm_specs From a81fdc8ec1a344f92a665a795e5088237b9781f9 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 29 Jan 2020 16:45:07 +0530 Subject: [PATCH 019/283] Revert back to original vat calculation --- utils/hosting_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index e20e9b16..da2540d6 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -106,7 +106,7 @@ def get_vm_price_for_given_vat(cpu, memory, ssd_size, hdd_size=0, discount_name = pricing.discount_name discount_amount = round(float(pricing.discount_amount), 2) - vat = (price - decimal.Decimal(discount_amount)) * decimal.Decimal(vat_rate) * decimal.Decimal(0.01) + vat = price * decimal.Decimal(vat_rate) * decimal.Decimal(0.01) vat_percent = vat_rate cents = decimal.Decimal('.01') From ad606c2c554a854e1499b7ec86b04d851f956e91 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 29 Jan 2020 16:50:05 +0530 Subject: [PATCH 020/283] Correct calculation of total price --- datacenterlight/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index f8f7f928..6dec71d2 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -677,13 +677,13 @@ class OrderConfirmationView(DetailView, FormView): vm_specs["vat"] = vat vm_specs["vat_percent"] = vat_percent vm_specs["vat_validation_status"] = request.session["vat_validation_status"] if "vat_validation_status" in request.session else "" - vm_specs["total_price"] = round(price + vm_specs["vat"] - discount['amount'], + vm_specs["total_price"] = round(price + vm_specs["vat"] - discount['amount_with_vat'], 2) vm_specs["vat_country"] = user_vat_country vm_specs["discount"] = discount vm_specs["price_with_vat"] = price + vm_specs["vat"] vm_specs["price_after_discount"] = round(price - discount['amount'], 2) - vm_specs["price_after_discount_with_vat"] = round((price - discount['amount']) + vm_specs["vat"], 2) + vm_specs["price_after_discount_with_vat"] = round((price - discount['amount_with_vat']) + vm_specs["vat"], 2) request.session['specs'] = vm_specs context.update({ From 8ee4081f6011af7c4506c42ec7c3b5b41c611a1e Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 29 Jan 2020 16:58:47 +0530 Subject: [PATCH 021/283] Fix round up calculations --- utils/hosting_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index da2540d6..5d898b0a 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -112,10 +112,12 @@ def get_vm_price_for_given_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_amount_with_vat = decimal.Decimal(discount_amount) * (1 + decimal.Decimal(vat_rate) * decimal.Decimal(0.01)) + discount_amount_with_vat = discount_amount_with_vat.quantize(cents, decimal.ROUND_HALF_UP) discount = { 'name': discount_name, 'amount': discount_amount, - 'amount_with_vat': round(discount_amount * (1 + vat_rate * 0.01), 2) + 'amount_with_vat': round(float(discount_amount_with_vat), 2) } return (round(float(price), 2), round(float(vat), 2), round(float(vat_percent), 2), discount) From 4128aeb64da8a964e9d0794fc0b9d095740fdd00 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 29 Jan 2020 17:21:59 +0530 Subject: [PATCH 022/283] Add line height for final price --- datacenterlight/static/datacenterlight/css/hosting.css | 1 + 1 file changed, 1 insertion(+) diff --git a/datacenterlight/static/datacenterlight/css/hosting.css b/datacenterlight/static/datacenterlight/css/hosting.css index 0f16ab77..bcf266cc 100644 --- a/datacenterlight/static/datacenterlight/css/hosting.css +++ b/datacenterlight/static/datacenterlight/css/hosting.css @@ -532,6 +532,7 @@ .order-detail-container .total-price { font-size: 18px; + line-height: 20px; } @media (max-width: 767px) { From f546c5cb4f032b7c071b50aee328c6b224cd27b8 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 29 Jan 2020 17:38:44 +0530 Subject: [PATCH 023/283] Increase content space in order detail desktop view --- .../templates/datacenterlight/order_detail.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index f62fd063..fbe6ef16 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -104,7 +104,7 @@ {{ request.session.template.name }}

-
+

{% trans "Cores" %}: {{vm.cpu|floatformat}} @@ -121,7 +121,7 @@


-
+

{% trans "Price Before VAT" %} {{vm.price|intcomma}} CHF @@ -130,7 +130,7 @@


-
+
-
+

{% trans "Cores" %}: {{vm.cpu|floatformat}} @@ -121,7 +132,7 @@


-
+

{% trans "Price Before VAT" %} {{vm.price|intcomma}} CHF @@ -130,64 +141,38 @@


-
- +
-
+

-
-

Pre VAT

+
+

{% trans "Pre VAT" %}

-
-

VAT for {{vm.vat_country}} ({{vm.vat_percent}}%)

+
+

{% trans "VAT for" %} {{vm.vat_country}} ({{vm.vat_percent}}%)

-
+

Price

-
+

{{vm.price|intcomma}} CHF

-
+

{{vm.price_with_vat|intcomma}} CHF

{% if vm.discount.amount > 0 %}
-
+

{{vm.discount.name}}

-
+

-{{vm.discount.amount|intcomma}} CHF

-
+

-{{vm.discount.amount_with_vat|intcomma}} CHF

@@ -196,15 +181,15 @@

-
+
-
+

Total

-
+

{{vm.price_after_discount|intcomma}} CHF

-
+

{{vm.price_after_discount_with_vat|intcomma}} CHF

@@ -212,11 +197,9 @@

-
-

+

{% trans "Your Price in Total" %} {{vm.total_price|floatformat:2|intcomma}} CHF -

{% endif %} From 3141dc279326b38cd0025f080b95ec558ea3ebd8 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 30 Jan 2020 11:52:29 +0530 Subject: [PATCH 025/283] Round price_with_vat --- datacenterlight/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 6dec71d2..2f411194 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -681,7 +681,7 @@ class OrderConfirmationView(DetailView, FormView): 2) vm_specs["vat_country"] = user_vat_country vm_specs["discount"] = discount - vm_specs["price_with_vat"] = price + vm_specs["vat"] + vm_specs["price_with_vat"] = round(price + vm_specs["vat"], 2) vm_specs["price_after_discount"] = round(price - discount['amount'], 2) vm_specs["price_after_discount_with_vat"] = round((price - discount['amount_with_vat']) + vm_specs["vat"], 2) request.session['specs'] = vm_specs From 7a9b315e2ed0de42eac0f4dc1199e3ace02abe92 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 30 Jan 2020 12:33:47 +0530 Subject: [PATCH 026/283] Add media query for device width less than 368px --- .../templates/datacenterlight/order_detail.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 3236ffe0..525a8a95 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -113,6 +113,15 @@ } } + @media screen and (max-width:367px){ + .cmf-ord-heading { + font-size: 13px; + } + .order-detail-container .order-details { + font-size: 12px; + } + } +
From f4393426d376e73ab13bb3b0cb8602cf5ef731a8 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 08:53:24 +0530 Subject: [PATCH 027/283] Fix proper VAT values --- datacenterlight/views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 2f411194..8da3e5c5 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -680,10 +680,11 @@ class OrderConfirmationView(DetailView, FormView): vm_specs["total_price"] = round(price + vm_specs["vat"] - discount['amount_with_vat'], 2) vm_specs["vat_country"] = user_vat_country - vm_specs["discount"] = discount - vm_specs["price_with_vat"] = round(price + vm_specs["vat"], 2) + vm_specs["price_with_vat"] = round(price * (1 + vm_specs["vat_percent"]), 2) vm_specs["price_after_discount"] = round(price - discount['amount'], 2) - vm_specs["price_after_discount_with_vat"] = round((price - discount['amount_with_vat']) + vm_specs["vat"], 2) + vm_specs["price_after_discount_with_vat"] = round((price - discount['amount']) * (1 + vm_specs["vat_percent"]), 2) + discount["amount_with_vat"] = vm_specs["price_with_vat"] - vm_specs["price_after_discount_with_vat"] + vm_specs["discount"] = discount request.session['specs'] = vm_specs context.update({ From b1acd3f25b716851ea4f0fd01a60af70f5756c9a Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 09:02:17 +0530 Subject: [PATCH 028/283] Convert VAT percent to CHF before calculations --- datacenterlight/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 8da3e5c5..943c3565 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -680,10 +680,10 @@ class OrderConfirmationView(DetailView, FormView): vm_specs["total_price"] = round(price + vm_specs["vat"] - discount['amount_with_vat'], 2) vm_specs["vat_country"] = user_vat_country - vm_specs["price_with_vat"] = round(price * (1 + vm_specs["vat_percent"]), 2) + vm_specs["price_with_vat"] = round(price * (1 + vm_specs["vat_percent"] * 0.01), 2) vm_specs["price_after_discount"] = round(price - discount['amount'], 2) - vm_specs["price_after_discount_with_vat"] = round((price - discount['amount']) * (1 + vm_specs["vat_percent"]), 2) - discount["amount_with_vat"] = vm_specs["price_with_vat"] - vm_specs["price_after_discount_with_vat"] + vm_specs["price_after_discount_with_vat"] = round((price - discount['amount']) * (1 + vm_specs["vat_percent"] * 0.01), 2) + discount["amount_with_vat"] = round(vm_specs["price_with_vat"] - vm_specs["price_after_discount_with_vat"], 2) vm_specs["discount"] = discount request.session['specs'] = vm_specs From 838163bd5953cdfde64f89bedd42db22bc5f9c56 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 09:15:12 +0530 Subject: [PATCH 029/283] Make total price consistent --- datacenterlight/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 943c3565..37635904 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -677,13 +677,12 @@ class OrderConfirmationView(DetailView, FormView): vm_specs["vat"] = vat vm_specs["vat_percent"] = vat_percent vm_specs["vat_validation_status"] = request.session["vat_validation_status"] if "vat_validation_status" in request.session else "" - vm_specs["total_price"] = round(price + vm_specs["vat"] - discount['amount_with_vat'], - 2) vm_specs["vat_country"] = user_vat_country vm_specs["price_with_vat"] = round(price * (1 + vm_specs["vat_percent"] * 0.01), 2) vm_specs["price_after_discount"] = round(price - discount['amount'], 2) vm_specs["price_after_discount_with_vat"] = round((price - discount['amount']) * (1 + vm_specs["vat_percent"] * 0.01), 2) discount["amount_with_vat"] = round(vm_specs["price_with_vat"] - vm_specs["price_after_discount_with_vat"], 2) + vm_specs["total_price"] = round(vm_specs["price_after_discount_with_vat"]) vm_specs["discount"] = discount request.session['specs'] = vm_specs From e6f00abd71c59dc788c88adb5e17d181dd3a443c Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 09:17:24 +0530 Subject: [PATCH 030/283] Do not round --- datacenterlight/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 37635904..4307fcc3 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -682,7 +682,7 @@ class OrderConfirmationView(DetailView, FormView): vm_specs["price_after_discount"] = round(price - discount['amount'], 2) vm_specs["price_after_discount_with_vat"] = round((price - discount['amount']) * (1 + vm_specs["vat_percent"] * 0.01), 2) discount["amount_with_vat"] = round(vm_specs["price_with_vat"] - vm_specs["price_after_discount_with_vat"], 2) - vm_specs["total_price"] = round(vm_specs["price_after_discount_with_vat"]) + vm_specs["total_price"] = vm_specs["price_after_discount_with_vat"] vm_specs["discount"] = discount request.session['specs'] = vm_specs From 918d2b17e1d476f2311fc9d6f6af5960c2272f57 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 12:13:56 +0530 Subject: [PATCH 031/283] Change invoice url --- .../hosting/virtual_machine_detail.html | 2 +- hosting/views.py | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/hosting/templates/hosting/virtual_machine_detail.html b/hosting/templates/hosting/virtual_machine_detail.html index 5873a2aa..36c04fed 100644 --- a/hosting/templates/hosting/virtual_machine_detail.html +++ b/hosting/templates/hosting/virtual_machine_detail.html @@ -46,7 +46,7 @@
{% trans "Current Pricing" %}
{{order.price|floatformat:2|intcomma}} CHF/{% if order.generic_product %}{% trans order.generic_product.product_subscription_interval %}{% else %}{% trans "Month" %}{% endif %}
- {% trans "See Invoice" %} + {% trans "See Invoice" %}
diff --git a/hosting/views.py b/hosting/views.py index 672868d8..b7bf07c8 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1687,13 +1687,27 @@ class VirtualMachineView(LoginRequiredMixin, View): context = None try: serializer = VirtualMachineSerializer(vm) + hosting_order = HostingOrder.objects.get( + vm_id=serializer.data['vm_id'] + ) + inv_url = None + if hosting_order.subscription_id: + stripe_obj = stripe.Invoice.list( + hosting_order.subscription_id + ) + inv_url = stripe_obj[0].data.hosted_invoice_url + elif hosting_order.stripe_charge_id: + stripe_obj = stripe.Charge.retrieve( + hosting_order.stripe_charge_id + ) + inv_url = stripe_obj.receipt_url context = { 'virtual_machine': serializer.data, - 'order': HostingOrder.objects.get( - vm_id=serializer.data['vm_id'] - ), - 'keys': UserHostingKey.objects.filter(user=request.user) + 'order': hosting_order, + 'keys': UserHostingKey.objects.filter(user=request.user), + 'inv_url': inv_url } + except Exception as ex: logger.debug("Exception generated {}".format(str(ex))) messages.error(self.request, From d8482c52f9d7d487ad1dcab7fa462686020db482 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 12:20:13 +0530 Subject: [PATCH 032/283] Get invoice correctly --- hosting/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/views.py b/hosting/views.py index b7bf07c8..1f30ba11 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1693,7 +1693,7 @@ class VirtualMachineView(LoginRequiredMixin, View): inv_url = None if hosting_order.subscription_id: stripe_obj = stripe.Invoice.list( - hosting_order.subscription_id + subscription=hosting_order.subscription_id ) inv_url = stripe_obj[0].data.hosted_invoice_url elif hosting_order.stripe_charge_id: From 9d21181073748d60b1f85759ce44e03a07324215 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 12:23:47 +0530 Subject: [PATCH 033/283] Get stripe invoice obj correctly --- hosting/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 1f30ba11..09e1131a 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1693,9 +1693,10 @@ class VirtualMachineView(LoginRequiredMixin, View): inv_url = None if hosting_order.subscription_id: stripe_obj = stripe.Invoice.list( - subscription=hosting_order.subscription_id + subscription=hosting_order.subscription_id, + count=0 ) - inv_url = stripe_obj[0].data.hosted_invoice_url + inv_url = stripe_obj.data[0].hosted_invoice_url elif hosting_order.stripe_charge_id: stripe_obj = stripe.Charge.retrieve( hosting_order.stripe_charge_id From b645f9894bbc0b67ac800353ed5f266fd438412a Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 12:25:51 +0530 Subject: [PATCH 034/283] Open invoice in a new window --- hosting/templates/hosting/virtual_machine_detail.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/templates/hosting/virtual_machine_detail.html b/hosting/templates/hosting/virtual_machine_detail.html index 36c04fed..24b2c6ad 100644 --- a/hosting/templates/hosting/virtual_machine_detail.html +++ b/hosting/templates/hosting/virtual_machine_detail.html @@ -46,7 +46,7 @@
{% trans "Current Pricing" %}
{{order.price|floatformat:2|intcomma}} CHF/{% if order.generic_product %}{% trans order.generic_product.product_subscription_interval %}{% else %}{% trans "Month" %}{% endif %}
- {% trans "See Invoice" %} + {% trans "See Invoice" %}
From 23b25002aeb713604c8b47e9814e5a8282bdc8d9 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 13:00:04 +0530 Subject: [PATCH 035/283] Take users to invoice url instead of orders Orders need a VAT alignment fix --- datacenterlight/tasks.py | 3 +- .../datacenterlight/order_detail.html | 36 +++++++++---------- datacenterlight/views.py | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/datacenterlight/tasks.py b/datacenterlight/tasks.py index 8b4626e8..55be8099 100644 --- a/datacenterlight/tasks.py +++ b/datacenterlight/tasks.py @@ -173,8 +173,7 @@ def create_vm_task(self, vm_template_id, user, specs, template, order_id): context = { 'base_url': "{0}://{1}".format(user.get('request_scheme'), user.get('request_host')), - 'order_url': reverse('hosting:orders', - kwargs={'pk': order_id}), + 'order_url': reverse('hosting:invoices'), 'page_header': _( 'Your New VM %(vm_name)s at Data Center Light') % { 'vm_name': vm.get('name')}, diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 525a8a95..6f9d43f2 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -103,26 +103,26 @@ {% trans "Product" %}:  {{ request.session.template.name }}

- +

diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 4307fcc3..385cf808 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -1154,7 +1154,7 @@ class OrderConfirmationView(DetailView, FormView): response = { 'status': True, 'redirect': ( - reverse('hosting:orders') + reverse('hosting:invoices') if request.user.is_authenticated() else reverse('datacenterlight:index') ), From 2058c660c0ea364bfb329255bc2ac5601b81204a Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 13:15:03 +0530 Subject: [PATCH 036/283] Retrieve only one invoice --- hosting/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/views.py b/hosting/views.py index 09e1131a..729d115b 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1694,7 +1694,7 @@ class VirtualMachineView(LoginRequiredMixin, View): if hosting_order.subscription_id: stripe_obj = stripe.Invoice.list( subscription=hosting_order.subscription_id, - count=0 + count=1 ) inv_url = stripe_obj.data[0].hosted_invoice_url elif hosting_order.stripe_charge_id: From c43afb7c590dccf0ce9e7b8b283d418f3869440b Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 13:47:29 +0530 Subject: [PATCH 037/283] Use round_up method --- datacenterlight/views.py | 10 +++++----- utils/hosting_utils.py | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 385cf808..d6bfd27d 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -29,7 +29,7 @@ from utils.forms import ( ) from utils.hosting_utils import ( get_vm_price_with_vat, get_all_public_keys, get_vat_rate_for_country, - get_vm_price_for_given_vat + get_vm_price_for_given_vat, round_up ) from utils.stripe_utils import StripeUtils from utils.tasks import send_plain_email_task @@ -678,10 +678,10 @@ class OrderConfirmationView(DetailView, FormView): vm_specs["vat_percent"] = vat_percent vm_specs["vat_validation_status"] = request.session["vat_validation_status"] if "vat_validation_status" in request.session else "" vm_specs["vat_country"] = user_vat_country - vm_specs["price_with_vat"] = round(price * (1 + vm_specs["vat_percent"] * 0.01), 2) - vm_specs["price_after_discount"] = round(price - discount['amount'], 2) - vm_specs["price_after_discount_with_vat"] = round((price - discount['amount']) * (1 + vm_specs["vat_percent"] * 0.01), 2) - discount["amount_with_vat"] = round(vm_specs["price_with_vat"] - vm_specs["price_after_discount_with_vat"], 2) + vm_specs["price_with_vat"] = round_up(price * (1 + vm_specs["vat_percent"] * 0.01), 2) + vm_specs["price_after_discount"] = round_up(price - discount['amount'], 2) + vm_specs["price_after_discount_with_vat"] = round_up((price - discount['amount']) * (1 + vm_specs["vat_percent"] * 0.01), 2) + discount["amount_with_vat"] = round_up(vm_specs["price_with_vat"] - vm_specs["price_after_discount_with_vat"], 2) vm_specs["total_price"] = vm_specs["price_after_discount_with_vat"] vm_specs["discount"] = discount request.session['specs'] = vm_specs diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 5d898b0a..7bff9a89 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -1,5 +1,6 @@ import decimal import logging +import math import subprocess from oca.pool import WrongIdError @@ -214,6 +215,11 @@ def get_ip_addresses(vm_id): return "--" +def round_up(n, decimals=0): + multiplier = 10 ** decimals + return math.ceil(n * multiplier) / multiplier + + class HostingUtils: @staticmethod def clear_items_from_list(from_list, items_list): From b103cff0a6742bea0a178914985ae7f29882e1db Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 13:54:29 +0530 Subject: [PATCH 038/283] Dont round_up discount (is obtained from subtraction) --- datacenterlight/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index d6bfd27d..185b3e29 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -681,9 +681,10 @@ class OrderConfirmationView(DetailView, FormView): vm_specs["price_with_vat"] = round_up(price * (1 + vm_specs["vat_percent"] * 0.01), 2) vm_specs["price_after_discount"] = round_up(price - discount['amount'], 2) vm_specs["price_after_discount_with_vat"] = round_up((price - discount['amount']) * (1 + vm_specs["vat_percent"] * 0.01), 2) - discount["amount_with_vat"] = round_up(vm_specs["price_with_vat"] - vm_specs["price_after_discount_with_vat"], 2) + discount["amount_with_vat"] = round(vm_specs["price_with_vat"] - vm_specs["price_after_discount_with_vat"], 2) vm_specs["total_price"] = vm_specs["price_after_discount_with_vat"] vm_specs["discount"] = discount + logger.debug(vm_specs) request.session['specs'] = vm_specs context.update({ From 8fe689d9933ae6c24c29df12b9b52b284ada2db0 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 15:23:26 +0530 Subject: [PATCH 039/283] Update some DE translations --- .../locale/de/LC_MESSAGES/django.po | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/datacenterlight/locale/de/LC_MESSAGES/django.po b/datacenterlight/locale/de/LC_MESSAGES/django.po index ebb78a1c..5ba12558 100644 --- a/datacenterlight/locale/de/LC_MESSAGES/django.po +++ b/datacenterlight/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-12-09 12:13+0000\n" +"POT-Creation-Date: 2020-02-01 09:42+0000\n" "PO-Revision-Date: 2018-03-30 23:22+0000\n" "Last-Translator: b'Anonymous User '\n" "Language-Team: LANGUAGE \n" @@ -144,7 +144,6 @@ msgid "" "the heart of Switzerland." msgstr "Bei uns findest Du die günstiges VMs aus der Schweiz." - msgid "Try now, order a VM. VM price starts from only 10.5 CHF per month." msgstr "Unser Angebot beginnt bei 10.5 CHF pro Monat. Probier's jetzt aus!" @@ -407,6 +406,17 @@ msgstr "Datum" msgid "Billed to" msgstr "Rechnungsadresse" +msgid "VAT Number" +msgstr "Mehrwertsteuernummer" + +msgid "Your VAT number has been verified" +msgstr "Deine Mehrwertsteuernummer wurde überprüft" + +msgid "" +"Your VAT number is under validation. VAT will be adjusted, once the " +"validation is complete." +msgstr "" + msgid "Payment method" msgstr "Bezahlmethode" @@ -437,8 +447,14 @@ msgstr "Beschreibung" msgid "Recurring" msgstr "Wiederholend" -msgid "Subtotal" -msgstr "Zwischensumme" +msgid "Price Before VAT" +msgstr "" + +msgid "Pre VAT" +msgstr "" + +msgid "Your Price in Total" +msgstr "" #, fuzzy, python-format #| msgid "" @@ -575,6 +591,9 @@ msgstr "Unser Angebot beginnt bei 15 CHF pro Monat. Probier's jetzt aus!" msgid "Actions speak louder than words. Let's do it, try our VM now." msgstr "Taten sagen mehr als Worte – Teste jetzt unsere VM!" +msgid "See Invoice" +msgstr "" + msgid "Invalid number of cores" msgstr "Ungültige Anzahle CPU-Kerne" @@ -665,6 +684,9 @@ msgstr "" "Deine VM ist gleich bereit. Wir senden Dir eine Bestätigungsemail, sobald Du " "auf sie zugreifen kannst." +#~ msgid "Subtotal" +#~ msgstr "Zwischensumme" + #~ msgid "VAT" #~ msgstr "Mehrwertsteuer" @@ -676,9 +698,6 @@ msgstr "" #~ "ausgelöst, nachdem Du die Bestellung auf der nächsten Seite bestätigt " #~ "hast." -#~ msgid "Card Number" -#~ msgstr "Kreditkartennummer" - #~ msgid "" #~ "You are not making any payment yet. After placing your order, you will be " #~ "taken to the Submit Payment Page." From 88a39ef85a6f9250900a28b0f1156a2fe51cc242 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 15:23:42 +0530 Subject: [PATCH 040/283] Update Changelog for 2.10 --- Changelog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Changelog b/Changelog index 566f5960..2c2d73d7 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +2.10: 2020-02-01 + * Feature: Introduce new design to show VAT exclusive/VAT inclusive pricing together + * Feature: Separate VAT and discount in Stripe + * Feature: Show Stripe invoices until we have a better way of showing them elegantly + * Bugfix: Fix bug where VAT is set to 0 because user set a valid VAT number before but later chose not to use any VAT number 2.9.5: 2020-01-20 * Feature: Show invoices directly from stripe (MR!727) 2.9.4: 2020-01-10 From 44dee625b4f0f5099a7ffd8d0dc43520ffe4069c Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 20:24:55 +0530 Subject: [PATCH 041/283] Add some DE translations --- datacenterlight/locale/de/LC_MESSAGES/django.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/datacenterlight/locale/de/LC_MESSAGES/django.po b/datacenterlight/locale/de/LC_MESSAGES/django.po index 5ba12558..2c9d0587 100644 --- a/datacenterlight/locale/de/LC_MESSAGES/django.po +++ b/datacenterlight/locale/de/LC_MESSAGES/django.po @@ -407,10 +407,10 @@ msgid "Billed to" msgstr "Rechnungsadresse" msgid "VAT Number" -msgstr "Mehrwertsteuernummer" +msgstr "MwSt-Nummer" msgid "Your VAT number has been verified" -msgstr "Deine Mehrwertsteuernummer wurde überprüft" +msgstr "Deine MwSt-Nummer wurde überprüft" msgid "" "Your VAT number is under validation. VAT will be adjusted, once the " @@ -451,7 +451,7 @@ msgid "Price Before VAT" msgstr "" msgid "Pre VAT" -msgstr "" +msgstr "Exkl. MwSt." msgid "Your Price in Total" msgstr "" From c765698a0f96618ee283fa309fa34b82f4e63d9e Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 2 Feb 2020 10:16:45 +0530 Subject: [PATCH 042/283] Add two columns for pricing --- .../datacenterlight/order_detail.html | 133 +++++++++++------- 1 file changed, 86 insertions(+), 47 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 6f9d43f2..80c5f459 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -58,52 +58,7 @@


{% trans "Order summary" %}

- {% if generic_payment_details %} -

- {% trans "Product" %}:  - {{ generic_payment_details.product_name }} -

-
-
- {% if generic_payment_details.vat_rate > 0 %} -

- {% trans "Price" %}: - CHF {{generic_payment_details.amount_before_vat|floatformat:2|intcomma}} -

-

- {% trans "VAT for" %} {{generic_payment_details.vat_country}} ({{generic_payment_details.vat_rate}}%) : - CHF {{generic_payment_details.vat_amount|floatformat:2|intcomma}} -

-

- {% trans "Total Amount" %} : - CHF {{generic_payment_details.amount|floatformat:2|intcomma}} -

- {% else %} -

- {% trans "Amount" %}: - CHF {{generic_payment_details.amount|floatformat:2|intcomma}} -

- {% endif %} - {% if generic_payment_details.description %} -

- {% trans "Description" %}: - {{generic_payment_details.description}} -

- {% endif %} - {% if generic_payment_details.recurring %} -

- {% trans "Recurring" %}: - Yes -

- {% endif %} -
-
- {% else %} -

- {% trans "Product" %}:  - {{ request.session.template.name }} -

- + + {% if generic_payment_details %} +

+ {% trans "Product" %}:  + {{ generic_payment_details.product_name }} +

+ {% if generic_payment_details.description %} +

+ {% trans "Description" %}: + {{generic_payment_details.description}} +

+ {% endif %} + {% if generic_payment_details.recurring %} +

+ {% trans "Recurring" %}: + Yes +

+ {% endif %} +
+
+
+
+
+
+

+ {% trans "Price Before VAT" %} + {{generic_payment_details.amount_before_vat|floatformat:2|intcomma}} CHF +

+
+
+
+
+
+
+
+

+
+
+

{% trans "Pre VAT" %}

+
+
+

{% trans "VAT for" %} {{generic_payment_details.vat_country}} ({{generic_payment_details.vat_percent}}%)

+
+
+
+
+

Price

+
+
+

{{generic_payment_details.amount_before_vat|floatformat:2|intcomma}} CHF

+
+
+

{{generic_payment_details.amount|floatformat:2|intcomma}} CHF

+
+
+
+
+
+
+
+
+
+

Total

+
+
+

{{generic_payment_details.amount_before_vat|floatformat:2|intcomma}} CHF

+
+
+

{{generic_payment_details.amount|floatformat:2|intcomma}} CHF

+
+
+
+
+
+
+
+ {% trans "Your Price in Total" %} + {{generic_payment_details.amount|floatformat:2|intcomma}} CHF +
+
+ {% else %} +

+ {% trans "Product" %}:  + {{ request.session.template.name }} +

From ffde015c3124eb87713ee61ba45644054fd7e14f Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 2 Feb 2020 10:26:13 +0530 Subject: [PATCH 043/283] Fix divs --- .../datacenterlight/order_detail.html | 113 +++++++++--------- 1 file changed, 55 insertions(+), 58 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 80c5f459..3e2ecf04 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -95,68 +95,65 @@ Yes

{% endif %} -
-
-
-
+
+
+
+
+

+ {% trans "Price Before VAT" %} + {{generic_payment_details.amount_before_vat|floatformat:2|intcomma}} CHF +

+
+
+
+
+
+
+
+

+
+
+

{% trans "Pre VAT" %}

+
+
+

{% trans "VAT for" %} {{generic_payment_details.vat_country}} ({{generic_payment_details.vat_rate}}%)

+
-
-

- {% trans "Price Before VAT" %} - {{generic_payment_details.amount_before_vat|floatformat:2|intcomma}} CHF -

+
+
+

Price

+
+
+

{{generic_payment_details.amount_before_vat|floatformat:2|intcomma}} CHF

+
+
+

{{generic_payment_details.amount|floatformat:2|intcomma}} CHF

+
-
-
-
-
-
-
-

-
-
-

{% trans "Pre VAT" %}

-
-
-

{% trans "VAT for" %} {{generic_payment_details.vat_country}} ({{generic_payment_details.vat_percent}}%)

-
-
-
-
-

Price

-
-
-

{{generic_payment_details.amount_before_vat|floatformat:2|intcomma}} CHF

-
-
-

{{generic_payment_details.amount|floatformat:2|intcomma}} CHF

-
-
-
-
-
-
-
-
-
-

Total

-
-
-

{{generic_payment_details.amount_before_vat|floatformat:2|intcomma}} CHF

-
-
-

{{generic_payment_details.amount|floatformat:2|intcomma}} CHF

-
-
-
-
-
-
-
- {% trans "Your Price in Total" %} - {{generic_payment_details.amount|floatformat:2|intcomma}} CHF +
+
+
+
+
+
+
+

Total

+
+
+

{{generic_payment_details.amount_before_vat|floatformat:2|intcomma}} CHF

+
+
+

{{generic_payment_details.amount|floatformat:2|intcomma}} CHF

+
+
+
+
+
+ {% trans "Your Price in Total" %} + {{generic_payment_details.amount|floatformat:2|intcomma}} CHF +
{% else %}

{% trans "Product" %}:  From 9f86f445695a5efc86048a41f37ccb5c60001b0a Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 2 Feb 2020 10:29:33 +0530 Subject: [PATCH 044/283] Add missing divs --- datacenterlight/templates/datacenterlight/order_detail.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 3e2ecf04..078f5efd 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -79,6 +79,8 @@ {% if generic_payment_details %} +

+

{% trans "Product" %}:  {{ generic_payment_details.product_name }} @@ -95,6 +97,7 @@ Yes

{% endif %} +

@@ -154,6 +157,7 @@ {% trans "Your Price in Total" %} {{generic_payment_details.amount|floatformat:2|intcomma}} CHF
+
{% else %}

{% trans "Product" %}:  From fc8c4579fb42197e29da7377b76f4a0b421f38c2 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 2 Feb 2020 10:41:51 +0530 Subject: [PATCH 045/283] Show prices to two decimals --- .../templates/datacenterlight/order_detail.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 078f5efd..b8cd7a4b 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -184,7 +184,7 @@

{% trans "Price Before VAT" %} - {{vm.price|intcomma}} CHF + {{vm.price|floatformat:2|intcomma}} CHF

@@ -207,10 +207,10 @@

Price

-

{{vm.price|intcomma}} CHF

+

{{vm.price|floatformat:2|intcomma}} CHF

-

{{vm.price_with_vat|intcomma}} CHF

+

{{vm.price_with_vat|floatformat:2|intcomma}} CHF

{% if vm.discount.amount > 0 %} @@ -219,10 +219,10 @@

{{vm.discount.name}}

-

-{{vm.discount.amount|intcomma}} CHF

+

-{{vm.discount.amount|floatformat:2|intcomma}} CHF

-

-{{vm.discount.amount_with_vat|intcomma}} CHF

+

-{{vm.discount.amount_with_vat|floatformat:2|intcomma}} CHF

{% endif %} @@ -236,10 +236,10 @@

Total

-

{{vm.price_after_discount|intcomma}} CHF

+

{{vm.price_after_discount|floatformat:2|intcomma}} CHF

-

{{vm.price_after_discount_with_vat|intcomma}} CHF

+

{{vm.price_after_discount_with_vat|floatformat:2|intcomma}} CHF

From c0683d9f538769791e3b2fd6623b9ca24a706a61 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 2 Feb 2020 10:57:14 +0530 Subject: [PATCH 046/283] Show prices to two decimal places --- datacenterlight/templatetags/custom_tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datacenterlight/templatetags/custom_tags.py b/datacenterlight/templatetags/custom_tags.py index 4cc50caa..0574d29f 100644 --- a/datacenterlight/templatetags/custom_tags.py +++ b/datacenterlight/templatetags/custom_tags.py @@ -106,7 +106,7 @@ def get_line_item_from_stripe_invoice(invoice): period = mark_safe("%s — %s" % ( datetime.datetime.fromtimestamp(start_date).strftime('%Y-%m-%d'), datetime.datetime.fromtimestamp(end_date).strftime('%Y-%m-%d'))), - total=invoice.total/100, + total='%.2f' % (invoice.total/100), stripe_invoice_url=invoice.hosted_invoice_url, see_invoice_text=_("See Invoice") )) From e094930d6eec56e523e182e299746601d2e0f046 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 2 Feb 2020 12:39:19 +0530 Subject: [PATCH 047/283] Show product name in invoices list if product is not a VM --- datacenterlight/templatetags/custom_tags.py | 29 +++++++++++++++++++-- hosting/templates/hosting/invoices.html | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/datacenterlight/templatetags/custom_tags.py b/datacenterlight/templatetags/custom_tags.py index 0574d29f..cb0fb6fa 100644 --- a/datacenterlight/templatetags/custom_tags.py +++ b/datacenterlight/templatetags/custom_tags.py @@ -1,12 +1,16 @@ import datetime +import logging from django import template from django.core.urlresolvers import resolve, reverse from django.utils.safestring import mark_safe from django.utils.translation import activate, get_language, ugettext_lazy as _ +from hosting.models import GenericProduct from utils.hosting_utils import get_ip_addresses +logger = logging.getLogger(__name__) + register = template.Library() @@ -72,8 +76,10 @@ def get_line_item_from_stripe_invoice(invoice): end_date = 0 is_first = True vm_id = -1 + plan_name = "" for line_data in invoice["lines"]["data"]: if is_first: + plan_name = line_data.plan.name start_date = line_data.period.start end_date = line_data.period.end is_first = False @@ -102,8 +108,9 @@ def get_line_item_from_stripe_invoice(invoice): """.format( vm_id=vm_id if vm_id > 0 else "", - ip_addresses=mark_safe(get_ip_addresses(vm_id)) if vm_id > 0 else "", - period = mark_safe("%s — %s" % ( + ip_addresses=mark_safe(get_ip_addresses(vm_id)) if vm_id > 0 else + mark_safe(plan_name), + period=mark_safe("%s — %s" % ( datetime.datetime.fromtimestamp(start_date).strftime('%Y-%m-%d'), datetime.datetime.fromtimestamp(end_date).strftime('%Y-%m-%d'))), total='%.2f' % (invoice.total/100), @@ -112,3 +119,21 @@ def get_line_item_from_stripe_invoice(invoice): )) else: return "" + + +def get_product_name(plan_name): + product_name = "" + if plan_name and plan_name.startswith("generic-"): + product_id = plan_name[plan_name.index("-") + 1:plan_name.rindex("-")] + try: + product = GenericProduct.objects.get(id=product_id) + product_name = product.product_name + except GenericProduct.DoesNotExist as dne: + logger.error("Generic product id=%s does not exist" % product_id) + product_name = "Unknown" + except GenericProduct.MultipleObjectsReturned as mor: + logger.error("Multiple products with id=%s exist" % product_id) + product_name = "Unknown" + else: + logger.debug("Product name for plan %s does not exist" % plan_name) + return product_name diff --git a/hosting/templates/hosting/invoices.html b/hosting/templates/hosting/invoices.html index f48802d1..1a97fd1f 100644 --- a/hosting/templates/hosting/invoices.html +++ b/hosting/templates/hosting/invoices.html @@ -19,7 +19,7 @@ {% trans "VM ID" %} - {% trans "IP Address" %} + {% trans "IP Address" %}/{% trans "Product" %} {% trans "Period" %} {% trans "Amount" %} From 42a4a77c0278cf2c4336a605f0d9b1715d9ba304 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 2 Feb 2020 12:42:19 +0530 Subject: [PATCH 048/283] Show product name --- datacenterlight/templatetags/custom_tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datacenterlight/templatetags/custom_tags.py b/datacenterlight/templatetags/custom_tags.py index cb0fb6fa..a2d9bec6 100644 --- a/datacenterlight/templatetags/custom_tags.py +++ b/datacenterlight/templatetags/custom_tags.py @@ -109,7 +109,7 @@ def get_line_item_from_stripe_invoice(invoice): """.format( vm_id=vm_id if vm_id > 0 else "", ip_addresses=mark_safe(get_ip_addresses(vm_id)) if vm_id > 0 else - mark_safe(plan_name), + mark_safe(get_product_name(plan_name)), period=mark_safe("%s — %s" % ( datetime.datetime.fromtimestamp(start_date).strftime('%Y-%m-%d'), datetime.datetime.fromtimestamp(end_date).strftime('%Y-%m-%d'))), From 70a3620598cf06f904c01276470096670b1c069f Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 2 Feb 2020 13:09:27 +0530 Subject: [PATCH 049/283] Fix getting product from plan_name --- datacenterlight/templatetags/custom_tags.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/datacenterlight/templatetags/custom_tags.py b/datacenterlight/templatetags/custom_tags.py index a2d9bec6..d86ba27d 100644 --- a/datacenterlight/templatetags/custom_tags.py +++ b/datacenterlight/templatetags/custom_tags.py @@ -124,13 +124,15 @@ def get_line_item_from_stripe_invoice(invoice): def get_product_name(plan_name): product_name = "" if plan_name and plan_name.startswith("generic-"): - product_id = plan_name[plan_name.index("-") + 1:plan_name.rindex("-")] + first_index_hyphen = plan_name.index("-") + 1 + product_id = plan_name[first_index_hyphen: + (plan_name[first_index_hyphen:].index("-")) + first_index_hyphen] try: product = GenericProduct.objects.get(id=product_id) product_name = product.product_name except GenericProduct.DoesNotExist as dne: logger.error("Generic product id=%s does not exist" % product_id) - product_name = "Unknown" + product_name = plan_name except GenericProduct.MultipleObjectsReturned as mor: logger.error("Multiple products with id=%s exist" % product_id) product_name = "Unknown" From a5d393ad20042770853dcb4c4765dac876b60a4b Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 2 Feb 2020 13:21:01 +0530 Subject: [PATCH 050/283] Right align prices --- datacenterlight/templatetags/custom_tags.py | 2 +- hosting/static/hosting/css/orders.css | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/datacenterlight/templatetags/custom_tags.py b/datacenterlight/templatetags/custom_tags.py index d86ba27d..0cb18e5b 100644 --- a/datacenterlight/templatetags/custom_tags.py +++ b/datacenterlight/templatetags/custom_tags.py @@ -102,7 +102,7 @@ def get_line_item_from_stripe_invoice(invoice): {vm_id} {ip_addresses} {period} - {total} + {total} {see_invoice_text} diff --git a/hosting/static/hosting/css/orders.css b/hosting/static/hosting/css/orders.css index 6819a94b..2deab999 100644 --- a/hosting/static/hosting/css/orders.css +++ b/hosting/static/hosting/css/orders.css @@ -2,4 +2,10 @@ .orders-container .table > tbody > tr > td { vertical-align: middle; +} + +@media screen and (min-width:767px){ + .dcl-text-right { + padding-right: 20px; + } } \ No newline at end of file From f0f8af23674f1be9b0bd353b507a7e33df249a78 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 2 Feb 2020 21:39:51 +0530 Subject: [PATCH 051/283] Change col-sm-8 to col-sm-9 to spread content further on desktop view --- .../datacenterlight/order_detail.html | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index b8cd7a4b..2897e3bf 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -80,7 +80,7 @@ {% if generic_payment_details %}
-
+

{% trans "Product" %}:  {{ generic_payment_details.product_name }} @@ -101,7 +101,7 @@


-
+

{% trans "Price Before VAT" %} {{generic_payment_details.amount_before_vat|floatformat:2|intcomma}} CHF @@ -110,7 +110,7 @@


-
+

@@ -137,7 +137,7 @@

-
+

Total

@@ -153,7 +153,7 @@

-
+
{% trans "Your Price in Total" %} {{generic_payment_details.amount|floatformat:2|intcomma}} CHF
@@ -164,7 +164,7 @@ {{ request.session.template.name }}

-
+

{% trans "Cores" %}: {{vm.cpu|floatformat}} @@ -181,7 +181,7 @@


-
+

{% trans "Price Before VAT" %} {{vm.price|floatformat:2|intcomma}} CHF @@ -190,7 +190,7 @@


-
+

@@ -230,7 +230,7 @@

-
+

Total

@@ -246,7 +246,7 @@

-
+
{% trans "Your Price in Total" %} {{vm.total_price|floatformat:2|intcomma}} CHF
From 1630dc195b96f839d249f2b2d64a97786a20e7aa Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 2 Feb 2020 21:52:48 +0530 Subject: [PATCH 052/283] Reduce header font size --- datacenterlight/templates/datacenterlight/order_detail.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 2897e3bf..5060f1cc 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -61,7 +61,7 @@