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
commit 0e28e50bac
4 changed files with 56 additions and 60 deletions

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