Save order specifications in HostingOrder also
This commit is contained in:
parent
5851277d9a
commit
900f014d92
3 changed files with 59 additions and 3 deletions
|
@ -1,12 +1,12 @@
|
|||
from django.contrib.sites.models import Site
|
||||
|
||||
from datacenterlight.tasks import create_vm_task
|
||||
from hosting.models import HostingOrder, HostingBill
|
||||
from hosting.models import HostingOrder, HostingBill, OrderSpecifications
|
||||
from membership.models import StripeCustomer
|
||||
from utils.forms import UserBillingAddressForm
|
||||
from utils.models import BillingAddress
|
||||
from .cms_models import CMSIntegration
|
||||
from .models import VMPricing
|
||||
from .models import VMPricing, VMTemplate
|
||||
|
||||
|
||||
def get_cms_integration(name):
|
||||
|
@ -53,6 +53,13 @@ def create_vm(billing_address_data, stripe_customer_id, specs,
|
|||
vm_pricing=vm_pricing
|
||||
)
|
||||
|
||||
order_specs_obj, obj_created = OrderSpecifications.objects.get_or_create(
|
||||
vm_template=VMTemplate.objects.get(vm_template_id),
|
||||
cores=specs['cpu'], memory=specs['memory'], ssd_size=specs['disk_size']
|
||||
)
|
||||
order.order_specs = order_specs_obj
|
||||
order.save()
|
||||
|
||||
# Create a Hosting Bill
|
||||
HostingBill.create(customer=customer, billing_address=billing_address)
|
||||
|
||||
|
|
35
hosting/migrations/0045_auto_20180701_1631.py
Normal file
35
hosting/migrations/0045_auto_20180701_1631.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.4 on 2018-07-01 16:31
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import utils.mixins
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('datacenterlight', '0024_dclcalculatorpluginmodel_vm_templates_to_show'),
|
||||
('hosting', '0044_hostingorder_vm_pricing'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='OrderSpecifications',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('cores', models.IntegerField(default=0)),
|
||||
('memory', models.IntegerField(default=0)),
|
||||
('hdd_size', models.IntegerField(default=0)),
|
||||
('ssd_size', models.IntegerField(default=0)),
|
||||
('vm_template', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='datacenterlight.VMTemplate')),
|
||||
],
|
||||
bases=(utils.mixins.AssignPermissionsMixin, models.Model),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='hostingorder',
|
||||
name='order_specs',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='hosting.OrderSpecifications'),
|
||||
),
|
||||
]
|
|
@ -7,7 +7,7 @@ from django.utils import timezone
|
|||
from django.utils.functional import cached_property
|
||||
from Crypto.PublicKey import RSA
|
||||
|
||||
from datacenterlight.models import VMPricing
|
||||
from datacenterlight.models import VMPricing, VMTemplate
|
||||
from membership.models import StripeCustomer, CustomUser
|
||||
from utils.models import BillingAddress
|
||||
from utils.mixins import AssignPermissionsMixin
|
||||
|
@ -41,6 +41,19 @@ class HostingPlan(models.Model):
|
|||
return price
|
||||
|
||||
|
||||
class OrderSpecifications(AssignPermissionsMixin, models.Model):
|
||||
vm_template = models.ForeignKey(VMTemplate, blank=True, null=True)
|
||||
cores = models.IntegerField(default=0)
|
||||
memory = models.IntegerField(default=0)
|
||||
hdd_size = models.IntegerField(default=0)
|
||||
ssd_size = models.IntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return "%s - %s cores, %s GB RAM, %s GB SSD" % (
|
||||
self.vm_template.name, self.cores, self.memory, self.ssd_size
|
||||
)
|
||||
|
||||
|
||||
class HostingOrder(AssignPermissionsMixin, models.Model):
|
||||
ORDER_APPROVED_STATUS = 'Approved'
|
||||
ORDER_DECLINED_STATUS = 'Declined'
|
||||
|
@ -56,6 +69,7 @@ class HostingOrder(AssignPermissionsMixin, models.Model):
|
|||
price = models.FloatField()
|
||||
subscription_id = models.CharField(max_length=100, null=True)
|
||||
vm_pricing = models.ForeignKey(VMPricing)
|
||||
order_specs = models.ForeignKey(OrderSpecifications, null=True, blank=True)
|
||||
|
||||
permissions = ('view_hostingorder',)
|
||||
|
||||
|
|
Loading…
Reference in a new issue