begin refactor product to user orders instead of single order

Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
Nico Schottelius 2020-08-09 14:38:10 +02:00
commit 8df1d8dc7c
10 changed files with 224 additions and 90 deletions

View file

@ -0,0 +1,41 @@
# Generated by Django 3.1 on 2020-08-09 12:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('uncloud_pay', '0013_auto_20200809_1237'),
('uncloud_vm', '0003_auto_20200808_1953'),
]
operations = [
migrations.RemoveField(
model_name='vmdiskproduct',
name='order',
),
migrations.RemoveField(
model_name='vmproduct',
name='order',
),
migrations.RemoveField(
model_name='vmsnapshotproduct',
name='order',
),
migrations.AddField(
model_name='vmdiskproduct',
name='orders',
field=models.ManyToManyField(to='uncloud_pay.Order'),
),
migrations.AddField(
model_name='vmproduct',
name='orders',
field=models.ManyToManyField(to='uncloud_pay.Order'),
),
migrations.AddField(
model_name='vmsnapshotproduct',
name='orders',
field=models.ManyToManyField(to='uncloud_pay.Order'),
),
]

View file

@ -58,13 +58,10 @@ class VMProduct(Product):
VMCluster, on_delete=models.CASCADE, editable=False, blank=True, null=True
)
# VM-specific. The name is only intended for customers: it's a pain to
# remember IDs (speaking from experience as ungleich customer)!
name = models.CharField(max_length=32, blank=True, null=True)
cores = models.IntegerField()
ram_in_gb = models.FloatField()
# Default recurring price is PER_MONTH, see uncloud_pay.models.Product.
@property
def recurring_price(self):
return self.cores * 3 + self.ram_in_gb * 4
@ -83,14 +80,7 @@ class VMProduct(Product):
def __str__(self):
name = f"{self.id}"
if self.name:
name = f"{self.id} ({self.name})"
return "VM {}: {} cores {} gb ram".format(name,
self.cores,
self.ram_in_gb)
return f"VM id={self.id},name={self.name},cores={self.cores},ram_in_gb={self.ram_in_gb}"
class VMWithOSProduct(VMProduct):
@ -165,7 +155,7 @@ class VMDiskProduct(Product):
default=VMDiskType.CEPH_SSD)
def __str__(self):
return f"Disk {self.size_in_gb}GB ({self.disk_type}) for VM '{self.vm.name}'"
return f"Disk {self.size_in_gb}GB ({self.disk_type}) for {self.vm}"
@property
def recurring_price(self):