add sample products and improve testing for Product
This commit is contained in:
parent
6a928a2b2a
commit
0dd1093812
4 changed files with 156 additions and 17 deletions
|
|
@ -596,7 +596,6 @@ class BillRecord(models.Model):
|
|||
|
||||
return record_delta.total_seconds()/self.order.recurring_period
|
||||
|
||||
|
||||
@property
|
||||
def sum(self):
|
||||
return self.order.price * Decimal(self.quantity)
|
||||
|
|
@ -604,6 +603,12 @@ class BillRecord(models.Model):
|
|||
def __str__(self):
|
||||
return f"{self.bill}: {self.quantity} x {self.order}"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.ending_date < self.starting_date:
|
||||
raise ValidationError("End date cannot be before starting date")
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
###
|
||||
# Products
|
||||
|
|
@ -703,13 +708,12 @@ class Product(UncloudModel):
|
|||
|
||||
@property
|
||||
def recurring_price(self):
|
||||
pass # To be implemented in child.
|
||||
""" implement correct values in the child class """
|
||||
return 0
|
||||
|
||||
@property
|
||||
def one_time_price(self):
|
||||
"""
|
||||
Default is 0 CHF
|
||||
"""
|
||||
""" implement correct values in the child class """
|
||||
return 0
|
||||
|
||||
|
||||
|
|
@ -799,3 +803,30 @@ class Product(UncloudModel):
|
|||
else:
|
||||
# FIXME: use the right type of exception here!
|
||||
raise Exception("Did not implement the discounter for this case")
|
||||
|
||||
# Sample products included into uncloud
|
||||
class SampleOneTimeProduct(Product):
|
||||
|
||||
default_recurring_period = RecurringPeriod.ONE_TIME
|
||||
|
||||
@property
|
||||
def one_time_price(self):
|
||||
return 5
|
||||
|
||||
class SampleRecurringProduct(Product):
|
||||
default_recurring_period = RecurringPeriod.PER_30D
|
||||
|
||||
@property
|
||||
def recurring_price(self):
|
||||
return 10
|
||||
|
||||
class SampleRecurringProductOneTimeFee(Product):
|
||||
default_recurring_period = RecurringPeriod.PER_30D
|
||||
|
||||
@property
|
||||
def one_time_price(self):
|
||||
return 5
|
||||
|
||||
@property
|
||||
def recurring_price(self):
|
||||
return 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue