Test that creating products w/o correct billing address fails
This commit is contained in:
parent
7b83efe995
commit
ab412cb877
3 changed files with 89 additions and 13 deletions
|
|
@ -789,8 +789,25 @@ class Product(UncloudModel):
|
|||
# FIXME: use the right type of exception here!
|
||||
raise Exception("Did not implement the discounter for this case")
|
||||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
try:
|
||||
ba = BillingAddress.get_address_for(self.owner)
|
||||
except BillingAddress.DoesNotExist:
|
||||
raise ValidationError("User does not have a billing address")
|
||||
|
||||
if not ba.active:
|
||||
raise ValidationError("User does not have an active billing address")
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
# Sample products included into uncloud
|
||||
class SampleOneTimeProduct(Product):
|
||||
"""
|
||||
Products are usually more complex, but this product shows how easy
|
||||
it can be to create your own one time product.
|
||||
"""
|
||||
|
||||
default_recurring_period = RecurringPeriod.ONE_TIME
|
||||
|
||||
|
|
@ -801,6 +818,11 @@ class SampleOneTimeProduct(Product):
|
|||
return self.ot_price
|
||||
|
||||
class SampleRecurringProduct(Product):
|
||||
"""
|
||||
Products are usually more complex, but this product shows how easy
|
||||
it can be to create your own recurring fee product.
|
||||
"""
|
||||
|
||||
default_recurring_period = RecurringPeriod.PER_30D
|
||||
|
||||
rc_price = models.IntegerField(default=10)
|
||||
|
|
@ -810,6 +832,11 @@ class SampleRecurringProduct(Product):
|
|||
return self.rc_price
|
||||
|
||||
class SampleRecurringProductOneTimeFee(Product):
|
||||
"""
|
||||
Products are usually more complex, but this product shows how easy
|
||||
it can be to create your own one time + recurring fee product.
|
||||
"""
|
||||
|
||||
default_recurring_period = RecurringPeriod.PER_30D
|
||||
|
||||
ot_price = models.IntegerField(default=5)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue