Revert "Commit WIP changes for /order, if needed at any point"

This reverts commit 83794a1781a1b84506100b39a6997882c654b4f3.
This commit is contained in:
fnux 2020-02-27 20:29:50 +01:00
parent 38d3a3a5d3
commit 0e28e50bac
4 changed files with 56 additions and 60 deletions

View file

@ -1,45 +0,0 @@
import uuid
from django.db import models
from django.contrib.auth import get_user_model
from django.utils.translation import gettext_lazy as _
# See https://docs.djangoproject.com/en/dev/ref/models/fields/#field-choices-enum-types
class RecurringPeriod(models.TextChoices):
ONE_TIME = 'ONCE', _('Onetime')
PER_YEAR = 'YEAR', _('Per Year')
PER_MONTH = 'MONTH', _('Per Month')
PER_MINUTE = 'MINUTE', _('Per Minute')
PER_DAY = 'DAY', _('Per Day')
PER_HOUR = 'HOUR', _('Per Hour')
PER_SECOND = 'SECOND', _('Per Second')
class Product(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
owner = models.ForeignKey(get_user_model(),
on_delete=models.CASCADE,
editable=False)
description = ""
status = models.CharField(max_length=256,
choices = (
('pending', 'Pending'),
('being_created', 'Being created'),
('active', 'Active'),
('deleted', 'Deleted')
),
default='pending'
)
order = models.ForeignKey('uncloud_pay.Order',
on_delete=models.CASCADE,
editable=False,
null=True)
@property
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
pass # To be implemented in child.
class Meta:
abstract = True

View file

@ -1,15 +1,23 @@
import uuid
from django.db import models
from django.contrib.auth import get_user_model
from django.core.validators import MinValueValidator
from django.utils.translation import gettext_lazy as _
from .helpers import RecurringPeriod
import uncloud_vm.models as vmmodels
import uuid
AMOUNT_MAX_DIGITS=10
AMOUNT_DECIMALS=2
# See https://docs.djangoproject.com/en/dev/ref/models/fields/#field-choices-enum-types
class RecurringPeriod(models.TextChoices):
ONE_TIME = 'ONCE', _('Onetime')
PER_YEAR = 'YEAR', _('Per Year')
PER_MONTH = 'MONTH', _('Per Month')
PER_MINUTE = 'MINUTE', _('Per Minute')
PER_DAY = 'DAY', _('Per Day')
PER_HOUR = 'HOUR', _('Per Hour')
PER_SECOND = 'SECOND', _('Per Second')
class Bill(models.Model):
owner = models.ForeignKey(get_user_model(),
on_delete=models.CASCADE)
@ -55,7 +63,8 @@ class Order(models.Model):
@property
def products(self):
# Blows up due to circular dependency...
vms = vmmodels.VMProduct.objects.all() #filter(order=self)
# vms = VMProduct.objects.filter(order=self)
vms = []
return vms
# def amount(self):
@ -107,3 +116,36 @@ class Payment(models.Model):
),
default='unknown')
timestamp = models.DateTimeField(editable=False)
class Product(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
owner = models.ForeignKey(get_user_model(),
on_delete=models.CASCADE,
editable=False)
description = ""
status = models.CharField(max_length=256,
choices = (
('pending', 'Pending'),
('being_created', 'Being created'),
('active', 'Active'),
('deleted', 'Deleted')
),
default='pending'
)
order = models.ForeignKey(Order,
on_delete=models.CASCADE,
editable=False,
null=True)
@property
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
pass # To be implemented in child.
class Meta:
abstract = True

View file

@ -23,7 +23,7 @@ class PaymentMethodSerializer(serializers.ModelSerializer):
fields = ['owner', 'primary', 'source', 'description']
class ProductSerializer(serializers.Serializer):
vms = VMProductSerializer(many=True, required=False, queryset=VMProduct.objects.all())
vms = VMProductSerializer(many=True, required=False)
def create(self, validated_data):
owner = validated_data.pop('owner')
@ -31,7 +31,7 @@ class ProductSerializer(serializers.Serializer):
vms = validated_data.pop('vms')
for vm in vms:
print(VMProduct.objects.create(owner=owner, order=order, **vm))
VMProduct.objects.create(owner=owner, order=order, **vm)
return True # FIXME: shoudl return created objects

View file

@ -1,10 +1,9 @@
import uuid
from django.db import models
from django.contrib.auth import get_user_model
import uuid
import uncloud_pay.models as paymodels
import uncloud_pay.helpers as payhelpers
from uncloud_pay.models import Product, RecurringPeriod
import uncloud_pay.models as pay_models
class VMHost(models.Model):
@ -34,7 +33,7 @@ class VMHost(models.Model):
)
class VMProduct(payhelpers.Product):
class VMProduct(Product):
vmhost = models.ForeignKey(VMHost,
on_delete=models.CASCADE,
editable=False,
@ -46,8 +45,8 @@ class VMProduct(payhelpers.Product):
ram_in_gb = models.FloatField()
@property
def recurring_price(self, recurring_period=paymodels.RecurringPeriod.PER_MONTH):
if recurring_period == paymodels.RecurringPeriod.PER_MONTH:
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
if recurring_period == RecurringPeriod.PER_MONTH:
# TODO: move magic numbers in variables
return self.cores * 3 + self.ram_in_gb * 2
else:
@ -80,7 +79,7 @@ class VMNetworkCard(models.Model):
mac_address = models.IntegerField()
class VMSnapshotProduct(payhelpers.Product):
class VMSnapshotProduct(Product):
price_per_gb_ssd = 0.35
price_per_gb_hdd = 1.5/100