From a091079677baa48ee27d4ce367933a934e5bd278 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 1 Aug 2020 23:20:14 +0200 Subject: [PATCH] in between commit Signed-off-by: Nico Schottelius --- .../commands/add-opennebula-vm-orders.py | 15 ++++++-- uncloud_pay/models.py | 35 +++++-------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/uncloud_pay/management/commands/add-opennebula-vm-orders.py b/uncloud_pay/management/commands/add-opennebula-vm-orders.py index d96e4c8..e07d3f5 100644 --- a/uncloud_pay/management/commands/add-opennebula-vm-orders.py +++ b/uncloud_pay/management/commands/add-opennebula-vm-orders.py @@ -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 + ) diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py index 122b806..662e51c 100644 --- a/uncloud_pay/models.py +++ b/uncloud_pay/models.py @@ -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)