implement basic logic for updating a recurring order
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
b8b15704a3
commit
9211894b23
2 changed files with 103 additions and 21 deletions
|
|
@ -65,26 +65,37 @@ class ProductTestCase(TestCase):
|
|||
|
||||
# One order
|
||||
p = SampleOneTimeProduct.objects.create(owner=self.user)
|
||||
p.create_order_at(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||
p.create_order(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||
|
||||
order_count = Order.objects.filter(owner=self.user).count()
|
||||
self.assertEqual(order_count, 1)
|
||||
|
||||
# One more order
|
||||
p = SampleRecurringProduct.objects.create(owner=self.user)
|
||||
p.create_order_at(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||
p.create_order(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||
|
||||
order_count = Order.objects.filter(owner=self.user).count()
|
||||
self.assertEqual(order_count, 2)
|
||||
|
||||
# Should create 2 orders
|
||||
p = SampleRecurringProductOneTimeFee.objects.create(owner=self.user)
|
||||
p.create_order_at(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||
p.create_order(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||
|
||||
order_count = Order.objects.filter(owner=self.user).count()
|
||||
self.assertEqual(order_count, 4)
|
||||
|
||||
|
||||
def test_update_recurring_order(self):
|
||||
"""
|
||||
Ensure creating orders from product only creates 1 order
|
||||
"""
|
||||
|
||||
p = SampleRecurringProduct.objects.create(owner=self.user)
|
||||
p.create_order(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||
|
||||
p.create_or_update_recurring_order(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||
|
||||
|
||||
class BillingAddressTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.user = get_user_model().objects.create(
|
||||
|
|
@ -351,6 +362,15 @@ class BillTestCase(TestCase):
|
|||
self.assertEqual(len(bills), 2)
|
||||
|
||||
|
||||
# TO BE IMPLEMENTED -- once orders can be marked as "done" / "inactive" / "not for billing"
|
||||
# def test_skip_disabled_orders(self):
|
||||
# """
|
||||
# Ensure that a bill only considers "active" orders
|
||||
# """
|
||||
|
||||
# self.assertEqual(1, 2)
|
||||
|
||||
|
||||
class ModifyProductTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.user = get_user_model().objects.create(
|
||||
|
|
@ -367,7 +387,7 @@ class ModifyProductTestCase(TestCase):
|
|||
|
||||
def test_no_pro_rata_first_bill(self):
|
||||
"""
|
||||
The bill should NOT contain a partial amount
|
||||
The bill should NOT contain a partial amount -- this is a BILL TEST :-)
|
||||
"""
|
||||
|
||||
price = 5
|
||||
|
|
@ -380,7 +400,7 @@ class ModifyProductTestCase(TestCase):
|
|||
ending_date = timezone.make_aware(datetime.datetime(2020,3,31))
|
||||
time_diff = (ending_date - starting_date).total_seconds()
|
||||
|
||||
product.create_order_at(starting_date)
|
||||
product.create_order(starting_date)
|
||||
|
||||
bills = Bill.create_next_bills_for_user(self.user,
|
||||
ending_date=ending_date)
|
||||
|
|
@ -394,6 +414,37 @@ class ModifyProductTestCase(TestCase):
|
|||
self.assertNotEqual(bills[0].sum, pro_rata_amount * price)
|
||||
self.assertEqual(bills[0].sum, price)
|
||||
|
||||
def test_bill_for_modified_product(self):
|
||||
"""
|
||||
The bill should NOT contain a partial amount -- this is a BILL TEST :-)
|
||||
"""
|
||||
|
||||
price = 5
|
||||
|
||||
# Standard 30d recurring product
|
||||
product = SampleRecurringProduct.objects.create(owner=self.user,
|
||||
rc_price=price)
|
||||
|
||||
starting_date = timezone.make_aware(datetime.datetime(2019,3,3))
|
||||
ending_date = timezone.make_aware(datetime.datetime(2019,3,31))
|
||||
change_date = timezone.make_aware(datetime.datetime(2019,4,17))
|
||||
|
||||
product.create_order(starting_date)
|
||||
|
||||
bills = Bill.create_next_bills_for_user(self.user,
|
||||
ending_date=ending_date)
|
||||
|
||||
product.rc_price = 10
|
||||
product.save()
|
||||
|
||||
product.create_or_update_recurring_order(when_to_start=change_date)
|
||||
|
||||
# expeted result:
|
||||
# 1x 5 chf bill record
|
||||
# 1x 5 chf bill record
|
||||
# 1x 10 partial bill record
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue