From c43afb7c590dccf0ce9e7b8b283d418f3869440b Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 1 Feb 2020 13:47:29 +0530 Subject: [PATCH] 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):