Update get_vm_price_with_vat: Return vat_percentage also

This commit is contained in:
PCoder 2018-04-17 21:36:08 +02:00
parent e4e7d93275
commit a50fa77c8a

View file

@ -93,7 +93,8 @@ def get_vm_price_with_vat(cpu, memory, ssd_size, hdd_size=0,
:param ssd_size: Disk space of the VM (SSD) :param ssd_size: Disk space of the VM (SSD)
:param hdd_size: The HDD size :param hdd_size: The HDD size
:param pricing_name: The pricing name to be used :param pricing_name: The pricing name to be used
:return: The a tuple containing the price of the VM and the VAT :return: The a tuple containing the price of the VM, the VAT and the
VAT percentage
""" """
try: try:
pricing = VMPricing.objects.get(name=pricing_name) pricing = VMPricing.objects.get(name=pricing_name)
@ -112,10 +113,12 @@ def get_vm_price_with_vat(cpu, memory, ssd_size, hdd_size=0,
(decimal.Decimal(hdd_size) * pricing.hdd_unit_price)) (decimal.Decimal(hdd_size) * pricing.hdd_unit_price))
if pricing.vat_inclusive: if pricing.vat_inclusive:
vat = decimal.Decimal(0) vat = decimal.Decimal(0)
vat_percent = decimal.Decimal(0)
else: else:
vat = price * pricing.vat_percentage * decimal.Decimal(0.01) vat = price * pricing.vat_percentage * decimal.Decimal(0.01)
vat_percent = pricing.vat_percentage
cents = decimal.Decimal('.01') cents = decimal.Decimal('.01')
price = price.quantize(cents, decimal.ROUND_HALF_UP) price = price.quantize(cents, decimal.ROUND_HALF_UP)
vat = vat.quantize(cents, decimal.ROUND_HALF_UP) vat = vat.quantize(cents, decimal.ROUND_HALF_UP)
return float(price), float(vat) return float(price), float(vat), float(vat_percent)