Make invoice for generic payment showable
This commit is contained in:
parent
d99271f71d
commit
a90bec98ec
2 changed files with 132 additions and 106 deletions
|
@ -39,7 +39,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
{% if order %}
|
{% if order and vm %}
|
||||||
<p>
|
<p>
|
||||||
<strong>{% trans "Status" %}: </strong>
|
<strong>{% trans "Status" %}: </strong>
|
||||||
<strong>
|
<strong>
|
||||||
|
@ -93,77 +93,97 @@
|
||||||
<hr>
|
<hr>
|
||||||
<div>
|
<div>
|
||||||
<h4>{% trans "Order summary" %}</h4>
|
<h4>{% trans "Order summary" %}</h4>
|
||||||
<p>
|
{% if vm %}
|
||||||
<strong>{% trans "Product" %}:</strong>
|
<p>
|
||||||
{% if vm.name %}
|
<strong>{% trans "Product" %}:</strong>
|
||||||
{{ vm.name }}
|
{% if vm.name %}
|
||||||
{% else %}
|
{{ vm.name }}
|
||||||
{{ request.session.template.name }}
|
{% else %}
|
||||||
{% endif %}
|
{{ request.session.template.name }}
|
||||||
</p>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-sm-6">
|
|
||||||
{% if vm.created_at %}
|
|
||||||
<p>
|
|
||||||
<span>{% trans "Period" %}: </span>
|
|
||||||
<span>
|
|
||||||
<span class="locale_date" data-format="YYYY/MM/DD">{{ vm.created_at|date:'Y-m-d h:i a' }}</span> - <span class="locale_date" data-format="YYYY/MM/DD">{{ subscription_end_date|date:'Y-m-d h:i a' }}</span>
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<p>
|
</p>
|
||||||
<span>{% trans "Cores" %}: </span>
|
<div class="row">
|
||||||
{% if vm.cores %}
|
|
||||||
<strong class="pull-right">{{vm.cores|floatformat}}</strong>
|
|
||||||
{% else %}
|
|
||||||
<strong class="pull-right">{{vm.cpu|floatformat}}</strong>
|
|
||||||
{% endif %}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<span>{% trans "Memory" %}: </span>
|
|
||||||
<strong class="pull-right">{{vm.memory}} GB</strong>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<span>{% trans "Disk space" %}: </span>
|
|
||||||
<strong class="pull-right">{{vm.disk_size}} GB</strong>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-12">
|
|
||||||
<hr class="thin-hr">
|
|
||||||
</div>
|
|
||||||
{% if vm.vat > 0 or vm.discount.amount > 0 %}
|
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="subtotal-price">
|
{% if vm.created_at %}
|
||||||
{% if vm.vat > 0 %}
|
<p>
|
||||||
<p>
|
<span>{% trans "Period" %}: </span>
|
||||||
<strong>{% trans "Subtotal" %} </strong>
|
<span>
|
||||||
<strong class="pull-right">{{vm.price|floatformat:2|intcomma}} CHF</strong>
|
<span class="locale_date" data-format="YYYY/MM/DD">{{ vm.created_at|date:'Y-m-d h:i a' }}</span> - <span class="locale_date" data-format="YYYY/MM/DD">{{ subscription_end_date|date:'Y-m-d h:i a' }}</span>
|
||||||
</p>
|
</span>
|
||||||
<p>
|
</p>
|
||||||
<small>{% trans "VAT" %} ({{ vm.vat_percent|floatformat:2|intcomma }}%) </small>
|
{% endif %}
|
||||||
<strong class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</strong>
|
<p>
|
||||||
</p>
|
<span>{% trans "Cores" %}: </span>
|
||||||
|
{% if vm.cores %}
|
||||||
|
<strong class="pull-right">{{vm.cores|floatformat}}</strong>
|
||||||
|
{% else %}
|
||||||
|
<strong class="pull-right">{{vm.cpu|floatformat}}</strong>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if vm.discount.amount > 0 %}
|
</p>
|
||||||
<p class="text-primary">
|
<p>
|
||||||
{%trans "Discount" as discount_name %}
|
<span>{% trans "Memory" %}: </span>
|
||||||
<strong>{{ vm.discount.name|default:discount_name }} </strong>
|
<strong class="pull-right">{{vm.memory}} GB</strong>
|
||||||
<strong class="pull-right">- {{ vm.discount.amount }} CHF</strong>
|
</p>
|
||||||
</p>
|
<p>
|
||||||
{% endif %}
|
<span>{% trans "Disk space" %}: </span>
|
||||||
</div>
|
<strong class="pull-right">{{vm.disk_size}} GB</strong>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<hr class="thin-hr">
|
<hr class="thin-hr">
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% if vm.vat > 0 or vm.discount.amount > 0 %}
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<p class="total-price">
|
<div class="subtotal-price">
|
||||||
<strong>{% trans "Total" %} </strong>
|
{% if vm.vat > 0 %}
|
||||||
<strong class="pull-right">{% if vm.total_price %}{{vm.total_price|floatformat:2|intcomma}}{% else %}{{vm.price|floatformat:2|intcomma}}{% endif %} CHF</strong>
|
<p>
|
||||||
</p>
|
<strong>{% trans "Subtotal" %} </strong>
|
||||||
|
<strong class="pull-right">{{vm.price|floatformat:2|intcomma}} CHF</strong>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<small>{% trans "VAT" %} ({{ vm.vat_percent|floatformat:2|intcomma }}%) </small>
|
||||||
|
<strong class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</strong>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
{% if vm.discount.amount > 0 %}
|
||||||
|
<p class="text-primary">
|
||||||
|
{%trans "Discount" as discount_name %}
|
||||||
|
<strong>{{ vm.discount.name|default:discount_name }} </strong>
|
||||||
|
<strong class="pull-right">- {{ vm.discount.amount }} CHF</strong>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<hr class="thin-hr">
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<p class="total-price">
|
||||||
|
<strong>{% trans "Total" %} </strong>
|
||||||
|
<strong class="pull-right">{% if vm.total_price %}{{vm.total_price|floatformat:2|intcomma}}{% else %}{{vm.price|floatformat:2|intcomma}}{% endif %} CHF</strong>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{% else %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<p>
|
||||||
|
<span>{% trans "Amount" %}: </span>
|
||||||
|
<strong class="pull-right">{{order.price|floatformat:2|intcomma}} CHF</strong>
|
||||||
|
</p>
|
||||||
|
{% if order.subscription_id %}
|
||||||
|
<p>
|
||||||
|
<span>{% trans "Recurring" %}: </span>
|
||||||
|
<strong class="pull-right">{{order.created_at|date:'d'|ordinal}} {% trans "of every month" %}</strong>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<hr class="thin-hr">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<hr class="thin-hr">
|
<hr class="thin-hr">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -862,32 +862,18 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView):
|
||||||
raise Http404
|
raise Http404
|
||||||
|
|
||||||
if obj is not None:
|
if obj is not None:
|
||||||
# invoice for previous order
|
if obj.generic_payment_id is not None:
|
||||||
try:
|
# generic payment case
|
||||||
vm_detail = VMDetail.objects.get(vm_id=obj.vm_id)
|
logger.debug("Generic payment case")
|
||||||
context['vm'] = vm_detail.__dict__
|
|
||||||
context['vm']['name'] = '{}-{}'.format(
|
else:
|
||||||
context['vm']['configuration'], context['vm']['vm_id'])
|
# invoice for previous order
|
||||||
price, vat, vat_percent, discount = get_vm_price_with_vat(
|
logger.debug("Invoice of VM order")
|
||||||
cpu=context['vm']['cores'],
|
|
||||||
ssd_size=context['vm']['disk_size'],
|
|
||||||
memory=context['vm']['memory'],
|
|
||||||
pricing_name=(obj.vm_pricing.name
|
|
||||||
if obj.vm_pricing else 'default')
|
|
||||||
)
|
|
||||||
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['subscription_end_date'] = vm_detail.end_date()
|
|
||||||
except VMDetail.DoesNotExist:
|
|
||||||
try:
|
try:
|
||||||
manager = OpenNebulaManager(
|
vm_detail = VMDetail.objects.get(vm_id=obj.vm_id)
|
||||||
email=owner.email, password=owner.password
|
context['vm'] = vm_detail.__dict__
|
||||||
)
|
context['vm']['name'] = '{}-{}'.format(
|
||||||
vm = manager.get_vm(obj.vm_id)
|
context['vm']['configuration'], context['vm']['vm_id'])
|
||||||
context['vm'] = VirtualMachineSerializer(vm).data
|
|
||||||
price, vat, vat_percent, discount = get_vm_price_with_vat(
|
price, vat, vat_percent, discount = get_vm_price_with_vat(
|
||||||
cpu=context['vm']['cores'],
|
cpu=context['vm']['cores'],
|
||||||
ssd_size=context['vm']['disk_size'],
|
ssd_size=context['vm']['disk_size'],
|
||||||
|
@ -899,23 +885,43 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView):
|
||||||
context['vm']['price'] = price
|
context['vm']['price'] = price
|
||||||
context['vm']['discount'] = discount
|
context['vm']['discount'] = discount
|
||||||
context['vm']['vat_percent'] = vat_percent
|
context['vm']['vat_percent'] = vat_percent
|
||||||
context['vm']['total_price'] = (
|
context['vm']['total_price'] = price + vat - discount['amount']
|
||||||
price + vat - discount['amount']
|
context['subscription_end_date'] = vm_detail.end_date()
|
||||||
)
|
except VMDetail.DoesNotExist:
|
||||||
except WrongIdError:
|
try:
|
||||||
messages.error(
|
manager = OpenNebulaManager(
|
||||||
self.request,
|
email=owner.email, password=owner.password
|
||||||
_('The VM you are looking for is unavailable at the '
|
)
|
||||||
'moment. Please contact Data Center Light support.')
|
vm = manager.get_vm(obj.vm_id)
|
||||||
)
|
context['vm'] = VirtualMachineSerializer(vm).data
|
||||||
self.kwargs['error'] = 'WrongIdError'
|
price, vat, vat_percent, discount = get_vm_price_with_vat(
|
||||||
context['error'] = 'WrongIdError'
|
cpu=context['vm']['cores'],
|
||||||
except ConnectionRefusedError:
|
ssd_size=context['vm']['disk_size'],
|
||||||
messages.error(
|
memory=context['vm']['memory'],
|
||||||
self.request,
|
pricing_name=(obj.vm_pricing.name
|
||||||
_('In order to create a VM, you need to create/upload '
|
if obj.vm_pricing else 'default')
|
||||||
'your SSH KEY first.')
|
)
|
||||||
)
|
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']
|
||||||
|
)
|
||||||
|
except WrongIdError:
|
||||||
|
messages.error(
|
||||||
|
self.request,
|
||||||
|
_('The VM you are looking for is unavailable at the '
|
||||||
|
'moment. Please contact Data Center Light support.')
|
||||||
|
)
|
||||||
|
self.kwargs['error'] = 'WrongIdError'
|
||||||
|
context['error'] = 'WrongIdError'
|
||||||
|
except ConnectionRefusedError:
|
||||||
|
messages.error(
|
||||||
|
self.request,
|
||||||
|
_('In order to create a VM, you need to create/upload '
|
||||||
|
'your SSH KEY first.')
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# new order, confirm payment
|
# new order, confirm payment
|
||||||
if 'token' in self.request.session:
|
if 'token' in self.request.session:
|
||||||
|
|
Loading…
Reference in a new issue