diff --git a/hosting/migrations/0031_hostingbill_total_price.py b/hosting/migrations/0031_hostingbill_total_price.py new file mode 100644 index 00000000..0a15c1f9 --- /dev/null +++ b/hosting/migrations/0031_hostingbill_total_price.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2017-05-06 12:30 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('hosting', '0030_hostingbill'), + ] + + operations = [ + migrations.AddField( + model_name='hostingbill', + name='total_price', + field=models.FloatField(default=0.0), + ), + ] diff --git a/hosting/models.py b/hosting/models.py index a27fb487..8c6a2c0d 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -238,6 +238,7 @@ class ManageVM(models.Model): class HostingBill(AssignPermissionsMixin, models.Model): customer = models.ForeignKey(StripeCustomer) billing_address = models.ForeignKey(BillingAddress) + total_price = models.FloatField(default=0.0) permissions = ('view_hostingbill',) diff --git a/hosting/templates/hosting/bill_detail.html b/hosting/templates/hosting/bill_detail.html index 1904bf82..b58c21f7 100644 --- a/hosting/templates/hosting/bill_detail.html +++ b/hosting/templates/hosting/bill_detail.html @@ -7,29 +7,29 @@
{# Adress bar #}
-
-

{% trans "Invoice"%}

{% trans "Order #"%} {{bill.id}}

-
+
+

{% trans "Invoice"%}

{% trans "Order #"%} {{bill.id}}

+

-
-
- {{bill.customer.user.name}}
- {{bill.billing_address.street_address}},{{bill.billing_address.postal_code}}
- {{bill.billing_address.city}}, {{bill.billing_address.country}}. -
-
-
-
- {% trans "ungleich GmbH" %}
- {% trans "buchhaltung@ungleich.ch" %}
- {% trans "Hauptstrasse 14"%}
- {% trans "CH-8775 Luchsingen"%}
- {% trans "Mwst-Nummer: CHE-109.549.333 MWST"%}
+
+
+ {{bill.customer.user.name}}
+ {{bill.billing_address.street_address}},{{bill.billing_address.postal_code}}
+ {{bill.billing_address.city}}, {{bill.billing_address.country}}. +
+
+
+
+ {% trans "ungleich GmbH" %}
+ {% trans "buchhaltung@ungleich.ch" %}
+ {% trans "Hauptstrasse 14"%}
+ {% trans "CH-8775 Luchsingen"%}
+ {% trans "Mwst-Nummer: CHE-109.549.333 MWST"%}
-
-
+
+

@@ -48,45 +48,42 @@ {% for vm in vms %} - - - - + + + + {% endfor %} {# Bill total#} - - - - - + +
{{ vm.name }}{{ vm.cores }}{{ vm.memory }}{{ vm.disk_size }}{{ vm.price }}{{ vm.cores }}{{ vm.memory|floatformat }} GiB {{ vm.disk_size|floatformat }} GiB {{ vm.price|floatformat }} CHF
{% trans "Total:" %} {% trans "Brutto" %} {% trans "Netto" %} {% trans "Total:" %} {{ bill.total_price}} CHF

{# Bill Footer #}
- {% trans "Alles Preise in CHF mit 8% Mehrwertsteuer." %} - {% trans "Betrag zahlbar innerhalb von 30 Tagen ab Rechnungseingang." %} - {% trans "Kontoverbindung:" %} -
-
- {% trans "IBAN:" %} -
-
- {% trans "BIC:" %} -
-
-
-
- {% trans "CH02 ............" %} -
-
- {% trans "POFICHBEXXX" %} -
-
+ {% trans "Alles Preise in CHF mit 8% Mehrwertsteuer." %} + {% trans "Betrag zahlbar innerhalb von 30 Tagen ab Rechnungseingang." %} + {% trans "Kontoverbindung:" %} +
+
+ {% trans "IBAN:" %} +
+
+ {% trans "BIC:" %} +
+
+
+
+ {% trans "CH02 ............" %} +
+
+ {% trans "POFICHBEXXX" %} +
+
{% endblock %} diff --git a/hosting/views.py b/hosting/views.py index c9634200..b552063a 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -448,9 +448,10 @@ class HostingBillDetailView(PermissionRequiredMixin, LoginRequiredMixin, DetailV # Get vm_pool for given user_id vm_pool = oca.VirtualMachinePool(client) vm_pool.info(filter=user_id) + # Reset total price + context['bill'].total_price = 0 # Add vm in vm_pool to context for vm in vm_pool: - #TODO: Replace with vm plan name = vm.name cores = int(vm.template.vcpu) memory = int(vm.template.memory) / 1024 @@ -461,12 +462,17 @@ class HostingBillDetailView(PermissionRequiredMixin, LoginRequiredMixin, DetailV disk_size += int(disk.size) / 1024 else: disk_size = int(vm.template.disk.size) / 1024 + + #TODO: Replace with vm plan + price = 0.6 * disk_size + 2 * memory + 5 * cores vm = {} vm['name'] = name - vm['price'] = 0.6 * disk_size + 2 * memory + 5 * cores + vm['price'] = price vm['disk_size'] = disk_size vm['cores'] = cores vm['memory'] = memory context['vms'].append(vm) + context['bill'].total_price += price + context['bill'].save() return context