[reverseDNS] add basic logic
This commit is contained in:
parent
20c7c86703
commit
ecc9e6f734
4 changed files with 53 additions and 5 deletions
|
|
@ -454,6 +454,16 @@ class Product(models.Model):
|
|||
|
||||
obj.recurring_periods.add(recurring_period, through_defaults= { 'is_default': True })
|
||||
|
||||
obj, created = cls.objects.get_or_create(name="reverse DNS",
|
||||
description="Reverse DNS network",
|
||||
currency=Currency.CHF,
|
||||
config={
|
||||
'parameters': [
|
||||
'network'
|
||||
]
|
||||
})
|
||||
obj.recurring_periods.add(recurring_period, through_defaults= { 'is_default': True })
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} - {self.description}"
|
||||
|
|
@ -968,6 +978,13 @@ class Order(models.Model):
|
|||
|
||||
return (one_time_price, recurring_price, config)
|
||||
|
||||
def check_parameters(self):
|
||||
if 'parameters' in self.product.config:
|
||||
for parameter in self.product.config['parameters']:
|
||||
if not parameter in self.config['parameters']:
|
||||
raise ValidationError(f"Required parameter '{parameter}' is missing.")
|
||||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# Calculate the price of the order when we create it
|
||||
# IMMUTABLE fields -- need to create new order to modify them
|
||||
|
|
@ -983,11 +1000,12 @@ class Order(models.Model):
|
|||
except ObjectDoesNotExist:
|
||||
raise ValidationError(f"Recurring Period {self.recurring_period} not allowed for product {self.product}")
|
||||
|
||||
self.check_parameters()
|
||||
|
||||
if self.ending_date and self.ending_date < self.starting_date:
|
||||
raise ValidationError("End date cannot be before starting date")
|
||||
|
||||
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue