From 73b590f48061b4057d93fa71f22646131aac9d3b Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 9 Dec 2019 14:42:05 +0530 Subject: [PATCH] Set EU VAT context for invoice_detail --- hosting/views.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index c5a4a761..157940fd 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1250,18 +1250,32 @@ class InvoiceDetailView(LoginRequiredMixin, DetailView): context['vm'] = vm_detail.__dict__ context['vm']['name'] = '{}-{}'.format( context['vm']['configuration'], context['vm']['vm_id']) - price, vat, vat_percent, discount = get_vm_price_with_vat( + user_vat_country = obj.order.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'], ssd_size=context['vm']['disk_size'], memory=context['vm']['memory'], - pricing_name=(obj.order.vm_pricing.name - if obj.order.vm_pricing else 'default') + pricing_name=(obj.vm_pricing.name + 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']['price'] = price - context['vm']['discount'] = discount - context['vm']['vat_percent'] = vat_percent - context['vm']['total_price'] = price + vat - discount['amount'] + context['vm']["after_eu_vat_intro"] = ( + True if obj.vm_id > settings.FIRST_VM_ID_AFTER_EU_VAT + else False + ) + 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) except VMDetail.DoesNotExist: # fallback to get it from the infrastructure try: