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