Apply country specific VAT rates for Generic Products
This commit is contained in:
parent
e0b2a0b6e2
commit
44a20a5029
3 changed files with 22 additions and 6 deletions
|
@ -26,7 +26,9 @@ from utils.forms import (
|
||||||
BillingAddressForm, BillingAddressFormSignup, UserBillingAddressForm,
|
BillingAddressForm, BillingAddressFormSignup, UserBillingAddressForm,
|
||||||
BillingAddress
|
BillingAddress
|
||||||
)
|
)
|
||||||
from utils.hosting_utils import get_vm_price_with_vat, get_all_public_keys
|
from utils.hosting_utils import (
|
||||||
|
get_vm_price_with_vat, get_all_public_keys, get_vat_rate_for_country
|
||||||
|
)
|
||||||
from utils.stripe_utils import StripeUtils
|
from utils.stripe_utils import StripeUtils
|
||||||
from utils.tasks import send_plain_email_task
|
from utils.tasks import send_plain_email_task
|
||||||
from .cms_models import DCLCalculatorPluginModel
|
from .cms_models import DCLCalculatorPluginModel
|
||||||
|
@ -414,8 +416,9 @@ class PaymentOrderView(FormView):
|
||||||
)
|
)
|
||||||
gp_details = {
|
gp_details = {
|
||||||
"product_name": product.product_name,
|
"product_name": product.product_name,
|
||||||
"amount": generic_payment_form.cleaned_data.get(
|
"amount": product.get_actual_price(
|
||||||
'amount'
|
explicit_vat=get_vat_rate_for_country(
|
||||||
|
address_form["country"])
|
||||||
),
|
),
|
||||||
"recurring": generic_payment_form.cleaned_data.get(
|
"recurring": generic_payment_form.cleaned_data.get(
|
||||||
'recurring'
|
'recurring'
|
||||||
|
|
|
@ -82,9 +82,10 @@ class GenericProduct(AssignPermissionsMixin, models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.product_name
|
return self.product_name
|
||||||
|
|
||||||
def get_actual_price(self):
|
def get_actual_price(self, vat_rate=None):
|
||||||
|
VAT = vat_rate if vat_rate is not None else self.product_vat
|
||||||
return round(
|
return round(
|
||||||
self.product_price + (self.product_price * self.product_vat), 2
|
self.product_price + (self.product_price * VAT), 2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import subprocess
|
||||||
from oca.pool import WrongIdError
|
from oca.pool import WrongIdError
|
||||||
|
|
||||||
from datacenterlight.models import VMPricing
|
from datacenterlight.models import VMPricing
|
||||||
from hosting.models import UserHostingKey, VMDetail
|
from hosting.models import UserHostingKey, VMDetail, VATRates
|
||||||
from opennebula_api.serializers import VirtualMachineSerializer
|
from opennebula_api.serializers import VirtualMachineSerializer
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -150,6 +150,18 @@ def ping_ok(host_ipv6):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def get_vat_rate_for_country(country):
|
||||||
|
vat_rate = VATRates.objects.get(
|
||||||
|
territory_codes=country, start_date__isnull=False, stop_date=None
|
||||||
|
)
|
||||||
|
if vat_rate:
|
||||||
|
logger.debug("VAT rate for %s is %s" % (country, vat_rate.rate))
|
||||||
|
return vat_rate.rate
|
||||||
|
else:
|
||||||
|
logger.debug("Did not find VAT rate for %s, returning 0" % country)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
class HostingUtils:
|
class HostingUtils:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def clear_items_from_list(from_list, items_list):
|
def clear_items_from_list(from_list, items_list):
|
||||||
|
|
Loading…
Reference in a new issue