Add total_price to HostingBill model

This commit is contained in:
Modulos 2017-05-06 14:44:08 +02:00
parent 2ff8b9e4a5
commit 673e8a0c79
4 changed files with 73 additions and 49 deletions

View file

@ -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),
),
]

View file

@ -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',)

View file

@ -7,29 +7,29 @@
<div class="container">
{# Adress bar #}
<div class="row">
<div class="invoice-title">
<h2>{% trans "Invoice"%}</h2><h3 class="pull-right">{% trans "Order #"%} {{bill.id}}</h3>
</div>
<div class="invoice-title">
<h2>{% trans "Invoice"%}</h2><h3 class="pull-right">{% trans "Order #"%} {{bill.id}}</h3>
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-6">
<address>
{{bill.customer.user.name}}<br>
{{bill.billing_address.street_address}},{{bill.billing_address.postal_code}}<br>
{{bill.billing_address.city}}, {{bill.billing_address.country}}.
</address>
</div>
<div class="col-sm-6 text-right">
<address>
{% trans "ungleich GmbH" %}<br>
{% trans "buchhaltung@ungleich.ch" %}<br>
{% trans "Hauptstrasse 14"%}<br>
{% trans "CH-8775 Luchsingen"%}<br>
{% trans "Mwst-Nummer: CHE-109.549.333 MWST"%}<br>
<div class="col-sm-6">
<address>
{{bill.customer.user.name}}<br>
{{bill.billing_address.street_address}},{{bill.billing_address.postal_code}}<br>
{{bill.billing_address.city}}, {{bill.billing_address.country}}.
</address>
</div>
<div class="col-sm-6 text-right">
<address>
{% trans "ungleich GmbH" %}<br>
{% trans "buchhaltung@ungleich.ch" %}<br>
{% trans "Hauptstrasse 14"%}<br>
{% trans "CH-8775 Luchsingen"%}<br>
{% trans "Mwst-Nummer: CHE-109.549.333 MWST"%}<br>
</address>
</div>
</address>
</div>
</div>
<hr>
<table class="table table-bordered">
@ -48,45 +48,42 @@
{% for vm in vms %}
<tr>
<td>{{ vm.name }}</td>
<td>{{ vm.cores }}</td>
<td>{{ vm.memory }}</td>
<td>{{ vm.disk_size }}</td>
<td>{{ vm.price }}</td>
<td><span class="pull-right">{{ vm.cores }}</span></td>
<td><span class="pull-right">{{ vm.memory|floatformat }} GiB </span></td>
<td><span class="pull-right">{{ vm.disk_size|floatformat }} GiB </span></td>
<td><span class="pull-right">{{ vm.price|floatformat }} CHF</span></td>
</tr>
{% endfor %}
{# Bill total#}
<tr>
<td> {% trans "Total:" %} </td>
<td> </td>
<td> </td>
<td> {% trans "Brutto" %} </td>
<td> {% trans "Netto" %} </td>
<td colspan=4> {% trans "Total:" %} </td>
<td> <span class="pull-right">{{ bill.total_price}} CHF </span></td>
</tr>
</tbody>
</table>
<hr>
{# Bill Footer #}
<div class="row">
{% trans "Alles Preise in CHF mit 8% Mehrwertsteuer." %}
{% trans "Betrag zahlbar innerhalb von 30 Tagen ab Rechnungseingang." %}
{% trans "Kontoverbindung:" %}
<div class="row">
<div class="col-sm-6">
{% trans "IBAN:" %}
</div>
<div class="col-sm-6">
{% trans "BIC:" %}
</div>
</div>
<div class="row">
<div class="col-sm-6">
{% trans "CH02 ............" %}
</div>
<div class="col-sm-6">
{% trans "POFICHBEXXX" %}
</div>
</div>
{% trans "Alles Preise in CHF mit 8% Mehrwertsteuer." %}
{% trans "Betrag zahlbar innerhalb von 30 Tagen ab Rechnungseingang." %}
{% trans "Kontoverbindung:" %}
<div class="row">
<div class="col-sm-6">
{% trans "IBAN:" %}
</div>
<div class="col-sm-6">
{% trans "BIC:" %}
</div>
</div>
<div class="row">
<div class="col-sm-6">
{% trans "CH02 ............" %}
</div>
<div class="col-sm-6">
{% trans "POFICHBEXXX" %}
</div>
</div>
</div>
</div>
{% endblock %}

View file

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