Refactor secret / local settings handling

This commit is contained in:
Nico Schottelius 2020-05-02 00:16:29 +02:00
commit 2cda6441f4
5 changed files with 60 additions and 60 deletions

View file

@ -4,7 +4,7 @@ from django.contrib.auth import get_user_model
from django.core.validators import MinValueValidator
from django.utils.translation import gettext_lazy as _
from django.utils import timezone
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ObjectDoesNotExist, ValidationError
import uuid
import logging
@ -811,7 +811,7 @@ class Order(models.Model):
# TODO: enforce ending_date - starting_date to be larger than recurring_period.
creation_date = models.DateTimeField(auto_now_add=True)
starting_date = models.DateTimeField()
starting_date = models.DateTimeField(default=timezone.now)
ending_date = models.DateTimeField(blank=True,
null=True)
@ -918,6 +918,17 @@ class Product(UncloudModel):
# _state.adding is switched to false after super(...) call.
being_created = self._state.adding
# First time saving - create an order
if not self.order:
billing_address = BillingAddress.get_preferred_address_for(self.owner)
if not billing_address:
raise ValidationError("Cannot create order without a billing address")
self.order = Order(owner=self.owner,
billing_address=billing_address)
super(Product, self).save(*args, **kwargs)
# Make sure we only create records on creation.