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

@ -48,20 +48,17 @@
{% 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>

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