in between commit

Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
Nico Schottelius 2020-08-01 23:20:14 +02:00
parent c9a941e290
commit a091079677
2 changed files with 21 additions and 29 deletions

View file

@ -48,8 +48,6 @@ class Command(BaseCommand):
)
orders = []
# 25206
vm25206 = VMProduct.objects.create(name="OpenNebula 25206",
cores=1,
@ -75,3 +73,16 @@ class Command(BaseCommand):
recurring_price = disk_price_2020(30, VMDiskType.CEPH_SSD) / 2,
description = vm25206_ssd
)
vm25206.cores = 2
vm25206.ram_in_gb = 8
vm25206.save()
order_vm_25206_growing = Order.objects.create(owner=user,
billing_address=addr,
starting_date=timezone.make_aware(datetime.datetime(2020,4,17)),
recurring_period=RecurringPeriod.PER_30D,
recurring_price = vm_price_2020(cpu=2, ram=8) / 2,
replaces=order_vm_25206,
description = "VM %s" % vm25206
)

View file

@ -332,6 +332,8 @@ class Order(models.Model):
blank=True,
null=True)
@property
def count_billed(self):
"""
@ -535,6 +537,8 @@ class Bill(models.Model):
pass
class BillRecord(models.Model):
"""
Entry of a bill, dynamically generated from an order.
@ -595,8 +599,6 @@ class OrderRecord(models.Model):
###
# Products
# Abstract (= no database representation) class used as parent for products
# (e.g. uncloud_vm.models.VMProduct).
class Product(UncloudModel):
owner = models.ForeignKey(get_user_model(),
on_delete=models.CASCADE,
@ -604,15 +606,15 @@ class Product(UncloudModel):
description = "Generic Product"
status = models.CharField(max_length=32,
choices=UncloudStatus.choices,
default=UncloudStatus.AWAITING_PAYMENT)
order = models.ForeignKey(Order,
on_delete=models.CASCADE,
editable=False,
null=True)
status = models.CharField(max_length=32,
choices=UncloudStatus.choices,
default=UncloudStatus.AWAITING_PAYMENT)
# Default period for all products
default_recurring_period = RecurringPeriod.PER_30D
@ -638,14 +640,6 @@ class Product(UncloudModel):
super().save(*args, **kwargs)
# # Make sure we only create records on creation.
# if being_created:
# record = OrderRecord(
# one_time_price=self.one_time_price,
# recurring_price=self.recurring_price,
# description=self.description)
# self.order.orderrecord_set.add(record, bulk=False)
@property
def recurring_price(self):
pass # To be implemented in child.
@ -736,16 +730,3 @@ class Product(UncloudModel):
else:
# FIXME: use the right type of exception here!
raise Exception("Did not implement the discounter for this case")
# Interesting snippets
# # Trigger initial bill generation at order creation.
# def save(self, *args, **kwargs):
# if self.ending_date and self.ending_date < self.starting_date:
# raise ValidationError("End date cannot be before starting date")
# super().save(*args, **kwargs)
# Bill.generate_for(self.starting_date.year, self.starting_date.month, self.owner)