remove uuid primary key
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
3ef19610f3
commit
1e68539ed8
53 changed files with 186 additions and 1249 deletions
|
|
@ -6,7 +6,6 @@ from django.core.validators import MinValueValidator
|
|||
from django.utils import timezone
|
||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||
|
||||
import uuid
|
||||
import logging
|
||||
from functools import reduce
|
||||
import itertools
|
||||
|
|
@ -77,8 +76,6 @@ class StripeCustomer(models.Model):
|
|||
# Payments and Payment Methods.
|
||||
|
||||
class Payment(models.Model):
|
||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
|
||||
owner = models.ForeignKey(get_user_model(),
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
|
|
@ -115,7 +112,6 @@ class Payment(models.Model):
|
|||
|
||||
|
||||
class PaymentMethod(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)
|
||||
|
|
@ -198,7 +194,6 @@ class PaymentMethod(models.Model):
|
|||
# Bills.
|
||||
|
||||
class BillingAddress(models.Model):
|
||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
|
||||
|
||||
organization = models.CharField(max_length=100)
|
||||
|
|
@ -208,6 +203,14 @@ class BillingAddress(models.Model):
|
|||
postal_code = models.CharField(max_length=50)
|
||||
country = CountryField(blank=True)
|
||||
vat_number = models.CharField(max_length=100, default="", blank=True)
|
||||
active = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=['owner'],
|
||||
condition=Q(primary=True),
|
||||
name='one_active_billing_address_per_user')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def get_addresses_for(user):
|
||||
|
|
@ -262,13 +265,13 @@ class Order(models.Model):
|
|||
bills. Do **NOT** mutate then!
|
||||
"""
|
||||
|
||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
owner = models.ForeignKey(get_user_model(),
|
||||
on_delete=models.CASCADE,
|
||||
editable=False)
|
||||
billing_address = models.ForeignKey(BillingAddress, on_delete=models.CASCADE)
|
||||
editable=True)
|
||||
|
||||
billing_address = models.ForeignKey(BillingAddress,
|
||||
on_delete=models.CASCADE)
|
||||
description = models.TextField()
|
||||
replaced_by = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True)
|
||||
|
||||
# TODO: enforce ending_date - starting_date to be larger than recurring_period.
|
||||
creation_date = models.DateTimeField(auto_now_add=True)
|
||||
|
|
@ -276,20 +279,6 @@ class Order(models.Model):
|
|||
ending_date = models.DateTimeField(blank=True,
|
||||
null=True)
|
||||
|
||||
# bill_records = models.ManyToManyField(BillRecord,
|
||||
# editable=False,
|
||||
# blank=True)
|
||||
|
||||
@property
|
||||
def count_billed(self):
|
||||
"""
|
||||
How many times this order was billed so far.
|
||||
This logic is mainly thought to be for recurring bills, but also works for one time bills
|
||||
"""
|
||||
|
||||
return sum([ br.usage_count for br in self.bill_records.all() ])
|
||||
|
||||
|
||||
recurring_period = models.IntegerField(choices = RecurringPeriod.choices,
|
||||
default = RecurringPeriod.PER_30D)
|
||||
|
||||
|
|
@ -315,6 +304,16 @@ class Order(models.Model):
|
|||
blank=True,
|
||||
null=True)
|
||||
|
||||
@property
|
||||
def count_billed(self):
|
||||
"""
|
||||
How many times this order was billed so far.
|
||||
This logic is mainly thought to be for recurring bills, but also works for one time bills
|
||||
"""
|
||||
|
||||
return sum([ br.usage_count for br in self.bill_records.all() ])
|
||||
|
||||
|
||||
def active_before(self, ending_date):
|
||||
# Was this order started before the specified ending date?
|
||||
if self.starting_date <= ending_date:
|
||||
|
|
@ -366,13 +365,6 @@ class Order(models.Model):
|
|||
owner=product.owner,
|
||||
**kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return "Order {} created at {}, {}->{}, recurring period {}. One time price {}, recurring price {}".format(
|
||||
self.uuid, self.creation_date,
|
||||
self.starting_date, self.ending_date,
|
||||
self.recurring_period,
|
||||
self.one_time_price,
|
||||
self.recurring_price)
|
||||
|
||||
@property
|
||||
def records(self):
|
||||
|
|
@ -398,8 +390,8 @@ class Order(models.Model):
|
|||
description=description)
|
||||
|
||||
def __str__(self):
|
||||
return "Order {} created at {}, {}->{}, recurring period {}. Price one time {}, recurring {}".format(
|
||||
self.uuid, self.creation_date,
|
||||
return "{} created at {}, {}->{}, recurring period {}. One time price {}, recurring price {}".format(
|
||||
self.id, self.creation_date,
|
||||
self.starting_date, self.ending_date,
|
||||
self.recurring_period,
|
||||
self.one_time_price,
|
||||
|
|
@ -411,7 +403,6 @@ class Bill(models.Model):
|
|||
Bill needs to be unique in the triple (owner, year, month)
|
||||
"""
|
||||
|
||||
# uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
owner = models.ForeignKey(get_user_model(),
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
|
|
@ -570,7 +561,6 @@ class OrderRecord(models.Model):
|
|||
# Abstract (= no database representation) class used as parent for products
|
||||
# (e.g. uncloud_vm.models.VMProduct).
|
||||
class Product(UncloudModel):
|
||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
owner = models.ForeignKey(get_user_model(),
|
||||
on_delete=models.CASCADE,
|
||||
editable=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue