[tests] back to 5 working tests!
This commit is contained in:
parent
8d8c4d660c
commit
58883765d7
4 changed files with 271 additions and 189 deletions
|
|
@ -592,6 +592,8 @@ class Order(models.Model):
|
|||
null=True)
|
||||
|
||||
|
||||
should_be_billed = models.BooleanField(default=True)
|
||||
|
||||
@property
|
||||
def earliest_ending_date(self):
|
||||
"""
|
||||
|
|
@ -702,24 +704,22 @@ class Order(models.Model):
|
|||
if self.ending_date and self.ending_date < self.starting_date:
|
||||
raise ValidationError("End date cannot be before starting date")
|
||||
|
||||
# do not check this if we upgrade
|
||||
# if self.ending_date and self.ending_date < self.earliest_ending_date:
|
||||
# raise ValidationError("Ending date is before minimum duration (starting_date + recurring period)")
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
def create_bill_record(self, bill):
|
||||
br = None
|
||||
|
||||
if self.is_one_time:
|
||||
if self.billrecord_set.count() == 0:
|
||||
br = BillRecord.objects.create(bill=bill,
|
||||
order=self,
|
||||
starting_date=self.starting_date,
|
||||
ending_date=self.ending_date)
|
||||
else:
|
||||
br = BillRecord.objects.filter(bill=bill, order=self).first()
|
||||
if self.one_time_price != 0 and self.billrecord_set.count() == 0:
|
||||
br = BillRecord.objects.create(bill=bill,
|
||||
order=self,
|
||||
starting_date=self.starting_date,
|
||||
ending_date=self.starting_date,
|
||||
is_recurring_record=False)
|
||||
|
||||
if self.recurring_price != 0:
|
||||
br = BillRecord.objects.filter(bill=bill, order=self, is_recurring_record=True).first()
|
||||
|
||||
if br:
|
||||
self.update_bill_record_for_recurring_order(br, bill)
|
||||
|
||||
|
|
@ -752,7 +752,7 @@ class Order(models.Model):
|
|||
Create a new bill record
|
||||
"""
|
||||
|
||||
last_bill_record = BillRecord.objects.filter(order=self).order_by('id').last()
|
||||
last_bill_record = BillRecord.objects.filter(order=self, is_recurring_record=True).order_by('id').last()
|
||||
|
||||
starting_date=self.starting_date
|
||||
|
||||
|
|
@ -772,9 +772,11 @@ class Order(models.Model):
|
|||
ending_date = self.get_ending_date_for_bill(bill)
|
||||
|
||||
return BillRecord.objects.create(bill=bill,
|
||||
order=self,
|
||||
starting_date=starting_date,
|
||||
ending_date=ending_date)
|
||||
order=self,
|
||||
starting_date=starting_date,
|
||||
ending_date=ending_date,
|
||||
is_recurring_record=True)
|
||||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
one_time_price = 0
|
||||
|
|
@ -799,7 +801,6 @@ class Order(models.Model):
|
|||
self.one_time_price = one_time_price
|
||||
self.recurring_price = recurring_price
|
||||
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
|
|
@ -1102,10 +1103,12 @@ class BillRecord(models.Model):
|
|||
starting_date = models.DateTimeField()
|
||||
ending_date = models.DateTimeField()
|
||||
|
||||
is_recurring_record = models.BooleanField(blank=False, null=False)
|
||||
|
||||
@property
|
||||
def quantity(self):
|
||||
""" Determine the quantity by the duration"""
|
||||
if self.order.is_one_time:
|
||||
if not self.is_recurring_record:
|
||||
return 1
|
||||
|
||||
record_delta = self.ending_date - self.starting_date
|
||||
|
|
@ -1114,10 +1117,18 @@ class BillRecord(models.Model):
|
|||
|
||||
@property
|
||||
def sum(self):
|
||||
return self.order.price * Decimal(self.quantity)
|
||||
if self.is_recurring_record:
|
||||
return self.order.recurring_price * Decimal(self.quantity)
|
||||
else:
|
||||
return self.order.one_time_price
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.bill}: {self.quantity} x {self.order}"
|
||||
if self.is_recurring_record:
|
||||
bill_line = f"{self.starting_date} - {self.ending_date}: {self.quantity} x {self.order}"
|
||||
else:
|
||||
bill_line = f"{self.starting_date}: {self.order}"
|
||||
|
||||
return bill_line
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.ending_date < self.starting_date:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue