Fix tests for billing

This commit is contained in:
Nico Schottelius 2020-08-09 10:18:15 +02:00
parent 89519e48a9
commit 6a928a2b2a
2 changed files with 12 additions and 4 deletions

View file

@ -327,7 +327,7 @@ class Order(models.Model):
One time orders have a recurring period of 0, so this work universally
"""
return self.starting_date + timedelta(seconds=self.recurring_period)
return self.starting_date + datetime.timedelta(seconds=self.recurring_period)
@property
@ -438,7 +438,7 @@ class Bill(models.Model):
starting_date = last_bill.starting_date
ending_date = bill.ending_date
else:
starting_date = last_bill.end_date + datetime.timedelta(seconds=1)
starting_date = last_bill.ending_date + datetime.timedelta(seconds=1)
else:
if first_order:
starting_date = first_order.starting_date
@ -566,6 +566,13 @@ class Bill(models.Model):
# For each recurring order get the usage and bill it
def close(self):
"""
Close/finish a bill
"""
self.is_final = True
self.save()
class BillRecord(models.Model):
"""

View file

@ -188,9 +188,10 @@ class BillAndOrderTestCase(TestCase):
"""
for ending_date in self.bill_dates:
Bill.create_next_bill_for_user(self.recurring_user, ending_date)
b = Bill.create_next_bill_for_user(self.recurring_user, ending_date)
b.close()
bills_count = Bill.objects.filter(owner=self.recurring_user).count()
bill_count = Bill.objects.filter(owner=self.recurring_user).count()
self.assertEqual(len(self.bill_dates), bill_count)