Set EU VAT context for invoice_detail

This commit is contained in:
PCoder 2019-12-09 14:42:05 +05:30
parent e940b468c4
commit 73b590f480

View file

@ -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: