pass first 2 bill tests

Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
Nico Schottelius 2020-08-08 22:31:43 +02:00
parent 9bf0a99f6a
commit db1a69561b
2 changed files with 18 additions and 13 deletions

View file

@ -399,8 +399,8 @@ class Bill(models.Model):
@property
def sum(self):
return 0
# for self.billrecord_set.
bill_records = BillRecord.objects.filter(bill=self)
return sum([ br.sum for br in bill_records ])
@classmethod
@ -525,9 +525,10 @@ class BillRecord(models.Model):
starting_date = models.DateTimeField()
ending_date = models.DateTimeField()
@property
def quantity(self):
""" Determine the quantity by the duration"""
if self.order.is_recurring:
if self.order.is_one_time:
return 1
record_delta = self.ending_date - self.starting_date
@ -535,6 +536,7 @@ class BillRecord(models.Model):
return record_delta.total_seconds()/self.order.recurring_period
@property
def sum(self):
return self.order.price * self.quantity

View file

@ -27,14 +27,7 @@ class ProductActivationTestCase(TestCase):
'description': 'One chocolate bar'
}
def test_bill_one_time_order(self):
one_time_price = 10
recurring_price = 150
description = "Test Product 1"
order = Order.objects.create(
self.one_time_order = Order.objects.create(
owner=self.user,
starting_date=self.order_meta[1]['starting_date'],
ending_date=self.order_meta[1]['ending_date'],
@ -44,15 +37,25 @@ class ProductActivationTestCase(TestCase):
billing_address=self.billing_address)
def test_bill_one_time_one_bill_record(self):
"""
Ensure there is only 1 bill record per order
"""
bill = Bill.create_next_bill_for_user(self.user)
self.assertEqual(order.billrecord_set.count(), 1)
self.assertEqual(self.one_time_order.billrecord_set.count(), 1)
def test_bill_sum(self):
"""
Ensure there is only 1 bill record per order
"""
bill = Bill.create_next_bill_for_user(self.user)
self.assertEqual(bill.sum, self.order_meta[1]['price'])
# class NotABillingTC(TestCase):
# #class BillingTestCase(TestCase):
# def setUp(self):