Make invoice EU VAT compatible

This commit is contained in:
PCoder 2019-12-09 12:30:49 +05:30
parent d8172d6bb2
commit d864f82e0f
4 changed files with 37 additions and 10 deletions

View file

@ -727,6 +727,7 @@ AUTH_SEED = env('AUTH_SEED')
AUTH_REALM = env('AUTH_REALM') AUTH_REALM = env('AUTH_REALM')
OTP_SERVER = env('OTP_SERVER') OTP_SERVER = env('OTP_SERVER')
OTP_VERIFY_ENDPOINT = env('OTP_VERIFY_ENDPOINT') OTP_VERIFY_ENDPOINT = env('OTP_VERIFY_ENDPOINT')
FIRST_VM_ID_AFTER_EU_VAT = env('FIRST_VM_ID_AFTER_EU_VAT')
if DEBUG: if DEBUG:

View file

@ -147,8 +147,12 @@
CHF</strong> CHF</strong>
</p> </p>
<p> <p>
<small>{% trans "VAT" %} ({{ vm.vat_percent|floatformat:2|intcomma }}%) {% if vm.after_eu_vat_intro %}
<small>{% trans "VAT for" %} {{vm.vat_country}} ({{vm.vat_percent}}%) : </small>
{% else %}
<small>{% trans "VAT" %} ({{ vm.vat_percent|floatformat:2|intcomma }}%)
</small> </small>
{% endif %}
<strong class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</strong> <strong class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</strong>
</p> </p>
{% endif %} {% endif %}

View file

@ -142,7 +142,12 @@
<strong class="pull-right">{{vm.price|floatformat:2|intcomma}} CHF</strong> <strong class="pull-right">{{vm.price|floatformat:2|intcomma}} CHF</strong>
</p> </p>
<p> <p>
<small>{% trans "VAT" %} ({{ vm.vat_percent|floatformat:2|intcomma }}%) </small> {% if vm.after_eu_vat_intro %}
<small>{% trans "VAT for" %} {{vm.vat_country}} ({{vm.vat_percent}}%) : </small>
{% else %}
<small>{% trans "VAT" %} ({{ vm.vat_percent|floatformat:2|intcomma }}%)
</small>
{% endif %}
<strong class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</strong> <strong class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</strong>
</p> </p>
{% endif %} {% endif %}

View file

@ -50,7 +50,10 @@ from utils.forms import (
ResendActivationEmailForm ResendActivationEmailForm
) )
from utils.hosting_utils import get_all_public_keys from utils.hosting_utils import get_all_public_keys
from utils.hosting_utils import get_vm_price_with_vat, HostingUtils from utils.hosting_utils import (
get_vm_price_with_vat, get_vm_price_for_given_vat, HostingUtils,
get_vat_rate_for_country
)
from utils.mailer import BaseEmail from utils.mailer import BaseEmail
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
@ -845,18 +848,32 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView, FormView):
context['vm'] = vm_detail.__dict__ context['vm'] = vm_detail.__dict__
context['vm']['name'] = '{}-{}'.format( context['vm']['name'] = '{}-{}'.format(
context['vm']['configuration'], context['vm']['vm_id']) context['vm']['configuration'], context['vm']['vm_id'])
price, vat, vat_percent, discount = get_vm_price_with_vat( user_vat_country = obj.billing_address.country
user_country_vat_rate = get_vat_rate_for_country(
user_vat_country)
price, vat, vat_percent, discount = get_vm_price_for_given_vat(
cpu=context['vm']['cores'], cpu=context['vm']['cores'],
ssd_size=context['vm']['disk_size'], ssd_size=context['vm']['disk_size'],
memory=context['vm']['memory'], memory=context['vm']['memory'],
pricing_name=(obj.vm_pricing.name pricing_name=(obj.vm_pricing.name
if obj.vm_pricing else 'default') if obj.vm_pricing else 'default'),
vat_rate= (
user_country_vat_rate * 100
if obj.vm_id > settings.FIRST_VM_ID_AFTER_EU_VAT
else 7.7
)
) )
context['vm']['vat'] = vat context['vm']["after_eu_vat_intro"] = (
context['vm']['price'] = price True if obj.vm_id > settings.FIRST_VM_ID_AFTER_EU_VAT
context['vm']['discount'] = discount else False
context['vm']['vat_percent'] = vat_percent )
context['vm']['total_price'] = price + vat - discount['amount'] context['vm']["price"] = price
context['vm']["vat"] = vat
context['vm']["vat_percent"] = vat_percent
context['vm']["vat_country"] = user_vat_country
context['vm']["discount"] = discount
context['vm']["total_price"] = round(
price + vat - discount['amount'], 2)
context['subscription_end_date'] = vm_detail.end_date() context['subscription_end_date'] = vm_detail.end_date()
except VMDetail.DoesNotExist: except VMDetail.DoesNotExist:
try: try: