Merge pull request 'bugfix-vm-detail-no-invoice' (#16) from bugfix-vm-detail-no-invoice into master

Reviewed-on: ungleich-public/dynamicweb#16
This commit is contained in:
pcoder116 2024-01-26 03:46:11 +00:00
commit 2e335fc574
2 changed files with 10 additions and 3 deletions

View file

@ -46,7 +46,7 @@
<div class="vm-vmid">
<div class="vm-item-subtitle">{% trans "Current Pricing" %}</div>
<div class="vm-item-lg">{{order.price|floatformat:2|intcomma}} CHF/{% if order.generic_product %}{% trans order.generic_product.product_subscription_interval %}{% else %}{% trans "Month" %}{% endif %}</div>
<a class="btn btn-vm-invoice" href="{{inv_url}}" target="_blank">{% trans "See Invoice" %}</a>
{% if inv_url %}<a class="btn btn-vm-invoice" href="{{inv_url}}" target="_blank">{% trans "See Invoice" %}</a>{%else%}{% trans "No invoice as of now" %}{% endif %}
</div>
</div>
<div class="vm-detail-item">

View file

@ -1694,7 +1694,11 @@ class VirtualMachineView(LoginRequiredMixin, View):
login_url = reverse_lazy('hosting:login')
def get_object(self):
owner = self.request.user
username = self.request.GET.get('username')
if self.request.user.is_admin and username:
owner = CustomUser.objects.get(username=username)
else:
owner = self.request.user
vm = None
manager = OpenNebulaManager(
email=owner.username,
@ -1750,7 +1754,10 @@ class VirtualMachineView(LoginRequiredMixin, View):
subscription=hosting_order.subscription_id,
count=1
)
inv_url = stripe_obj.data[0].hosted_invoice_url
if stripe_obj.data:
inv_url = stripe_obj.data[0].hosted_invoice_url
else:
inv_url = ''
elif hosting_order.stripe_charge_id:
stripe_obj = stripe.Charge.retrieve(
hosting_order.stripe_charge_id