Add total_price to HostingBill model
This commit is contained in:
		
					parent
					
						
							
								2ff8b9e4a5
							
						
					
				
			
			
				commit
				
					
						673e8a0c79
					
				
			
		
					 4 changed files with 73 additions and 49 deletions
				
			
		
							
								
								
									
										20
									
								
								hosting/migrations/0031_hostingbill_total_price.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								hosting/migrations/0031_hostingbill_total_price.py
									
										
									
									
									
										Normal 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),
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
| 
						 | 
					@ -238,6 +238,7 @@ class ManageVM(models.Model):
 | 
				
			||||||
class HostingBill(AssignPermissionsMixin, models.Model):
 | 
					class HostingBill(AssignPermissionsMixin, models.Model):
 | 
				
			||||||
    customer = models.ForeignKey(StripeCustomer)
 | 
					    customer = models.ForeignKey(StripeCustomer)
 | 
				
			||||||
    billing_address = models.ForeignKey(BillingAddress)
 | 
					    billing_address = models.ForeignKey(BillingAddress)
 | 
				
			||||||
 | 
					    total_price = models.FloatField(default=0.0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    permissions = ('view_hostingbill',)
 | 
					    permissions = ('view_hostingbill',)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,29 +7,29 @@
 | 
				
			||||||
<div class="container">
 | 
					<div class="container">
 | 
				
			||||||
	{# Adress bar  #}
 | 
						{# Adress bar  #}
 | 
				
			||||||
    <div class="row">
 | 
					    <div class="row">
 | 
				
			||||||
            <div class="invoice-title">
 | 
					        <div class="invoice-title">
 | 
				
			||||||
                <h2>{% trans "Invoice"%}</h2><h3 class="pull-right">{% trans "Order #"%} {{bill.id}}</h3>
 | 
					            <h2>{% trans "Invoice"%}</h2><h3 class="pull-right">{% trans "Order #"%} {{bill.id}}</h3>
 | 
				
			||||||
            </div>
 | 
					        </div>
 | 
				
			||||||
	</div>
 | 
						</div>
 | 
				
			||||||
    <hr>
 | 
					    <hr>
 | 
				
			||||||
	<div class="row">
 | 
						<div class="row">
 | 
				
			||||||
                <div class="col-sm-6">
 | 
					        <div class="col-sm-6">
 | 
				
			||||||
                    <address>
 | 
					            <address>
 | 
				
			||||||
                        {{bill.customer.user.name}}<br>
 | 
					                {{bill.customer.user.name}}<br>
 | 
				
			||||||
                        {{bill.billing_address.street_address}},{{bill.billing_address.postal_code}}<br>
 | 
					                {{bill.billing_address.street_address}},{{bill.billing_address.postal_code}}<br>
 | 
				
			||||||
                        {{bill.billing_address.city}}, {{bill.billing_address.country}}.
 | 
					                {{bill.billing_address.city}}, {{bill.billing_address.country}}.
 | 
				
			||||||
                    </address>
 | 
					            </address>
 | 
				
			||||||
                </div>
 | 
					        </div>
 | 
				
			||||||
                <div class="col-sm-6 text-right">
 | 
					        <div class="col-sm-6 text-right">
 | 
				
			||||||
                    <address>
 | 
					            <address>
 | 
				
			||||||
							{% trans "ungleich GmbH" %}<br>
 | 
						    			{% trans "ungleich GmbH" %}<br>
 | 
				
			||||||
							{% trans "buchhaltung@ungleich.ch" %}<br>
 | 
						    			{% trans "buchhaltung@ungleich.ch" %}<br>
 | 
				
			||||||
							{% trans "Hauptstrasse 14"%}<br>
 | 
						    			{% trans "Hauptstrasse 14"%}<br>
 | 
				
			||||||
							{% trans "CH-8775 Luchsingen"%}<br>
 | 
						    			{% trans "CH-8775 Luchsingen"%}<br>
 | 
				
			||||||
							{% trans "Mwst-Nummer: CHE-109.549.333 MWST"%}<br>
 | 
						    			{% trans "Mwst-Nummer: CHE-109.549.333 MWST"%}<br>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    </address>
 | 
					            </address>
 | 
				
			||||||
				</div>
 | 
						    </div>
 | 
				
			||||||
	</div>
 | 
						</div>
 | 
				
			||||||
	<hr>
 | 
						<hr>
 | 
				
			||||||
	<table class="table table-bordered"> 
 | 
						<table class="table table-bordered"> 
 | 
				
			||||||
| 
						 | 
					@ -48,45 +48,42 @@
 | 
				
			||||||
            {% for vm in vms %}
 | 
					            {% for vm in vms %}
 | 
				
			||||||
                <tr>
 | 
					                <tr>
 | 
				
			||||||
                    <td>{{ vm.name }}</td>
 | 
					                    <td>{{ vm.name }}</td>
 | 
				
			||||||
                    <td>{{ vm.cores }}</td>
 | 
					                    <td><span class="pull-right">{{ vm.cores }}</span></td>
 | 
				
			||||||
                    <td>{{ vm.memory }}</td>
 | 
					                    <td><span class="pull-right">{{ vm.memory|floatformat }} GiB </span></td>
 | 
				
			||||||
                    <td>{{ vm.disk_size }}</td>
 | 
					                    <td><span class="pull-right">{{ vm.disk_size|floatformat }} GiB </span></td>
 | 
				
			||||||
                    <td>{{ vm.price }}</td>
 | 
					                    <td><span class="pull-right">{{ vm.price|floatformat }} CHF</span></td>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                </tr>
 | 
					                </tr>
 | 
				
			||||||
            {% endfor %}
 | 
					            {% endfor %}
 | 
				
			||||||
	        {# Bill total#}
 | 
						        {# Bill total#}
 | 
				
			||||||
            <tr>
 | 
					            <tr>
 | 
				
			||||||
                <td> {% trans "Total:" %} </td>
 | 
					                <td colspan=4> {% trans "Total:" %} </td>
 | 
				
			||||||
                <td>  </td>
 | 
					                <td> <span class="pull-right">{{ bill.total_price}} CHF </span></td> 
 | 
				
			||||||
                <td>  </td>
 | 
					 | 
				
			||||||
                <td> {% trans "Brutto" %} </td>
 | 
					 | 
				
			||||||
                <td> {% trans "Netto" %} </td>
 | 
					 | 
				
			||||||
            </tr>
 | 
					            </tr>
 | 
				
			||||||
        </tbody>
 | 
					        </tbody>
 | 
				
			||||||
    </table>
 | 
					    </table>
 | 
				
			||||||
	<hr>
 | 
						<hr>
 | 
				
			||||||
    {# Bill Footer #}
 | 
					    {# Bill Footer #}
 | 
				
			||||||
	<div class="row">
 | 
						<div class="row">
 | 
				
			||||||
			{% trans "Alles Preise in CHF mit 8% Mehrwertsteuer." %}
 | 
						    {% trans "Alles Preise in CHF mit 8% Mehrwertsteuer." %}
 | 
				
			||||||
			{% trans "Betrag zahlbar innerhalb von 30 Tagen ab Rechnungseingang." %}
 | 
						    {% trans "Betrag zahlbar innerhalb von 30 Tagen ab Rechnungseingang." %}
 | 
				
			||||||
			{% trans "Kontoverbindung:" %}
 | 
						    {% trans "Kontoverbindung:" %}
 | 
				
			||||||
			<div class="row">
 | 
						    <div class="row">
 | 
				
			||||||
				<div class="col-sm-6">
 | 
						    	<div class="col-sm-6">
 | 
				
			||||||
					{% trans "IBAN:" %}
 | 
						    		{% trans "IBAN:" %}
 | 
				
			||||||
				</div>
 | 
						    	</div>
 | 
				
			||||||
				<div class="col-sm-6">
 | 
						    	<div class="col-sm-6">
 | 
				
			||||||
					{% trans "BIC:" %}
 | 
						    		{% trans "BIC:" %}
 | 
				
			||||||
				</div>
 | 
						    	</div>
 | 
				
			||||||
			</div>
 | 
						    </div>
 | 
				
			||||||
			<div class="row">
 | 
						    <div class="row">
 | 
				
			||||||
				<div class="col-sm-6">
 | 
						    	<div class="col-sm-6">
 | 
				
			||||||
					{% trans "CH02 ............" %}
 | 
						    		{% trans "CH02 ............" %}
 | 
				
			||||||
				</div>
 | 
						    	</div>
 | 
				
			||||||
				<div class="col-sm-6">
 | 
						    	<div class="col-sm-6">
 | 
				
			||||||
					{% trans "POFICHBEXXX" %}
 | 
						    		{% trans "POFICHBEXXX" %}
 | 
				
			||||||
				</div>
 | 
						    	</div>
 | 
				
			||||||
			</div>
 | 
						    </div>
 | 
				
			||||||
	</div>
 | 
						</div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
{% endblock %}
 | 
					{% endblock %}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -448,9 +448,10 @@ class HostingBillDetailView(PermissionRequiredMixin, LoginRequiredMixin, DetailV
 | 
				
			||||||
        # Get vm_pool for given user_id
 | 
					        # Get vm_pool for given user_id
 | 
				
			||||||
        vm_pool = oca.VirtualMachinePool(client)
 | 
					        vm_pool = oca.VirtualMachinePool(client)
 | 
				
			||||||
        vm_pool.info(filter=user_id)
 | 
					        vm_pool.info(filter=user_id)
 | 
				
			||||||
 | 
					        # Reset total price
 | 
				
			||||||
 | 
					        context['bill'].total_price = 0 
 | 
				
			||||||
        # Add vm in vm_pool to context
 | 
					        # Add vm in vm_pool to context
 | 
				
			||||||
        for vm in vm_pool:
 | 
					        for vm in vm_pool:
 | 
				
			||||||
            #TODO: Replace with vm plan 
 | 
					 | 
				
			||||||
            name = vm.name
 | 
					            name = vm.name
 | 
				
			||||||
            cores = int(vm.template.vcpu)
 | 
					            cores = int(vm.template.vcpu)
 | 
				
			||||||
            memory = int(vm.template.memory) / 1024
 | 
					            memory = int(vm.template.memory) / 1024
 | 
				
			||||||
| 
						 | 
					@ -461,12 +462,17 @@ class HostingBillDetailView(PermissionRequiredMixin, LoginRequiredMixin, DetailV
 | 
				
			||||||
                    disk_size += int(disk.size) / 1024
 | 
					                    disk_size += int(disk.size) / 1024
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                disk_size = int(vm.template.disk.size) / 1024
 | 
					                disk_size = int(vm.template.disk.size) / 1024
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            #TODO: Replace with vm plan 
 | 
				
			||||||
 | 
					            price = 0.6 * disk_size + 2 * memory + 5 * cores
 | 
				
			||||||
            vm = {}
 | 
					            vm = {}
 | 
				
			||||||
            vm['name'] = name
 | 
					            vm['name'] = name
 | 
				
			||||||
            vm['price'] = 0.6 * disk_size + 2 * memory + 5 * cores
 | 
					            vm['price'] = price
 | 
				
			||||||
            vm['disk_size'] = disk_size
 | 
					            vm['disk_size'] = disk_size
 | 
				
			||||||
            vm['cores'] = cores 
 | 
					            vm['cores'] = cores 
 | 
				
			||||||
            vm['memory'] = memory
 | 
					            vm['memory'] = memory
 | 
				
			||||||
            context['vms'].append(vm)
 | 
					            context['vms'].append(vm)
 | 
				
			||||||
 | 
					            context['bill'].total_price += price
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        context['bill'].save()
 | 
				
			||||||
        return context
 | 
					        return context
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue