Show VAT for eu countries only

This commit is contained in:
PCoder 2019-12-31 17:28:11 +05:30
parent aba3092207
commit 3ca7e89f4f
4 changed files with 32 additions and 14 deletions

View file

@ -33,12 +33,14 @@
{{billing_address.street_address}}, {{billing_address.postal_code}}<br> {{billing_address.street_address}}, {{billing_address.postal_code}}<br>
{{billing_address.city}}, {{billing_address.country}} {{billing_address.city}}, {{billing_address.country}}
{% if billing_address.vat_number %} {% if billing_address.vat_number %}
<br/>{% trans "VAT Number" %} {{billing_address.vat_number}}&nbsp; <br/>{% trans "VAT Number" %} {{billing_address.vat_number}}
{% if vm.vat_validation_status == "verified" %} {% if vm.vat_validation_status != "ch_vat" and vm.vat_validation_status != "not_needed" %}
<span class="fa fa-fw fa-check-circle" aria-hidden="true" title='{% trans "Your VAT number has been verified" %}'></span> {% if vm.vat_validation_status == "verified" %}
{% else %} <span class="fa fa-fw fa-check-circle" aria-hidden="true" title='{% trans "Your VAT number has been verified" %}'></span>
<span class="fa fa-fw fa-info-circle" aria-hidden="true" title='{% trans "Your VAT number is under validation. VAT will be adjusted, once the validation is complete." %}'></span> {% else %}
{% endif %} <span class="fa fa-fw fa-info-circle" aria-hidden="true" title='{% trans "Your VAT number is under validation. VAT will be adjusted, once the validation is complete." %}'></span>
{% endif %}
{% endif %}
{% endif %} {% endif %}
{% endwith %} {% endwith %}
</p> </p>

View file

@ -18,6 +18,11 @@ from .models import VMPricing, VMTemplate
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
eu_countries = ['at', 'be', 'bg', 'ch', 'cy', 'cz', 'hr', 'dk',
'ee', 'fi', 'fr', 'mc', 'de', 'gr', 'hu', 'ie', 'it',
'lv', 'lu', 'mt', 'nl', 'po', 'pt', 'ro','sk', 'si', 'es',
'se', 'gb']
def get_cms_integration(name): def get_cms_integration(name):
current_site = Site.objects.get_current() current_site = Site.objects.get_current()
@ -158,6 +163,11 @@ def validate_vat_number(stripe_customer_id, billing_address_id,
if billing_address is not None: if billing_address is not None:
logger.debug("BillingAddress found: %s %s type=%s" % ( logger.debug("BillingAddress found: %s %s type=%s" % (
billing_address_id, str(billing_address), type(billing_address))) billing_address_id, str(billing_address), type(billing_address)))
if billing_address.country.lower().strip() not in eu_countries:
return {
"validated_on": "",
"status": "not_needed"
}
if billing_address.vat_number_validated_on: if billing_address.vat_number_validated_on:
logger.debug("billing_address verified on %s" % logger.debug("billing_address verified on %s" %
billing_address.vat_number_validated_on) billing_address.vat_number_validated_on)

View file

@ -562,7 +562,7 @@ class PaymentOrderView(FormView):
request.session["vat_validation_status"] = validate_result["status"] request.session["vat_validation_status"] = validate_result["status"]
# For generic payment we take the user directly to confirmation # For generic payment we take the user directly to confirmation
if ('generic_payment_type' in request.session and if ('generic_p`ayment_type' in request.session and
self.request.session['generic_payment_type'] == 'generic'): self.request.session['generic_payment_type'] == 'generic'):
return HttpResponseRedirect( return HttpResponseRedirect(
reverse('datacenterlight:order_confirmation')) reverse('datacenterlight:order_confirmation'))
@ -617,7 +617,8 @@ class OrderConfirmationView(DetailView, FormView):
if ('generic_payment_type' in request.session and if ('generic_payment_type' in request.session and
self.request.session['generic_payment_type'] == 'generic'): self.request.session['generic_payment_type'] == 'generic'):
if request.session["vat_validation_status"] == "verified": if (request.session["vat_validation_status"] == "verified" or
request.session["vat_validation_status"] == "not_needed"):
request.session['generic_payment_details']['vat_rate'] = 0 request.session['generic_payment_details']['vat_rate'] = 0
request.session['generic_payment_details']['vat_amount'] = 0 request.session['generic_payment_details']['vat_amount'] = 0
request.session['generic_payment_details']['amount'] = request.session['generic_payment_details']['amount_before_vat'] request.session['generic_payment_details']['amount'] = request.session['generic_payment_details']['amount_before_vat']
@ -661,11 +662,13 @@ class OrderConfirmationView(DetailView, FormView):
if user_vat_country.lower() == "ch": if user_vat_country.lower() == "ch":
vm_specs["vat"] = vat vm_specs["vat"] = vat
vm_specs["vat_percent"] = vat_percent vm_specs["vat_percent"] = vat_percent
vm_specs["vat_validation_status"] = "ch_vat"
elif ("vat_validation_status" in request.session and elif ("vat_validation_status" in request.session and
request.session["vat_validation_status"] == "verified"): (request.session["vat_validation_status"] == "verified" or
request.session["vat_validation_status"] == "not_needed")):
vm_specs["vat_percent"] = 0 vm_specs["vat_percent"] = 0
vm_specs["vat"] = 0 vm_specs["vat"] = 0
vm_specs["vat_validation_status"] = "verified" vm_specs["vat_validation_status"] = request.session["vat_validation_status"]
else: else:
vm_specs["vat"] = vat vm_specs["vat"] = vat
vm_specs["vat_percent"] = vat_percent vm_specs["vat_percent"] = vat_percent

View file

@ -27,10 +27,13 @@
{% bootstrap_field field show_label=False type='fields' bound_css_class='' %} {% bootstrap_field field show_label=False type='fields' bound_css_class='' %}
{% endfor %} {% endfor %}
{% if form.instance.vat_number %} {% if form.instance.vat_number %}
{% if form.instance.vat_validation_status == "verified" %} {% if form.instance.vat_validation_status != "ch_vat" and form.instance.vat_validation_status != "not_needed" %}
<span class="fa fa-fw fa-check-circle" aria-hidden="true" title='{% trans "Your VAT number has been verified" %}'></span>
{% elif form.instance.vat_validation_status == "pending" %} {% if form.instance.vat_validation_status == "verified" %}
<span class="fa fa-fw fa-info-circle" aria-hidden="true" title='{% trans "Your VAT number is under validation. VAT will be adjusted, once the validation is complete." %}'></span> <span class="fa fa-fw fa-check-circle" aria-hidden="true" title='{% trans "Your VAT number has been verified" %}'></span>
{% elif form.instance.vat_validation_status == "pending" %}
<span class="fa fa-fw fa-info-circle" aria-hidden="true" title='{% trans "Your VAT number is under validation. VAT will be adjusted, once the validation is complete." %}'></span>
{% endif %}
{% endif %} {% endif %}
{% endif %} {% endif %}
<div class="form-group text-right"> <div class="form-group text-right">