begin splitting bill record creation function
This commit is contained in:
parent
18f9a3848a
commit
1c7d81762d
3 changed files with 185 additions and 52 deletions
|
|
@ -414,53 +414,95 @@ 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):
|
||||
def test_bill_for_increasing_product_easy(self):
|
||||
"""
|
||||
Modify a product, see one pro rata entry
|
||||
Modify product, check general logi
|
||||
"""
|
||||
|
||||
price = 5
|
||||
|
||||
# Standard 30d recurring product
|
||||
product = SampleRecurringProduct.objects.create(owner=self.user,
|
||||
rc_price=price)
|
||||
|
||||
# Create product
|
||||
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))
|
||||
|
||||
bill_ending_date = timezone.make_aware(datetime.datetime(2019,4,30))
|
||||
|
||||
starting_price = 10
|
||||
product = SampleRecurringProduct.objects.create(owner=self.user,
|
||||
rc_price=starting_price)
|
||||
product.create_order(starting_date)
|
||||
|
||||
product.rc_price = 10
|
||||
change1_date = timezone.make_aware(datetime.datetime(2019,4,17))
|
||||
product.rc_price = 20
|
||||
product.save()
|
||||
product.create_or_update_recurring_order(when_to_start=change1_date)
|
||||
|
||||
product.create_or_update_recurring_order(when_to_start=change_date)
|
||||
|
||||
bill_ending_date = timezone.make_aware(datetime.datetime(2019,6,30))
|
||||
bills = Bill.create_next_bills_for_user(self.user,
|
||||
ending_date=bill_ending_date)
|
||||
|
||||
# Sum:
|
||||
# recurring1 = 5 CHF -> for 30days
|
||||
# recurring2 = 5 CHF -> from 3rd of April to 3rd of May
|
||||
# recurring3 = 10 CHF -> from 17th of April to ... 17th of May?
|
||||
bill = bills[0]
|
||||
bill_records = BillRecord.objects.filter(bill=bill)
|
||||
|
||||
# If replacing lower order with higher:
|
||||
# - close the lower order NOW
|
||||
# - start higher order NOW+1s
|
||||
# If replacing higher order with lower order:
|
||||
# higher order continues until its end
|
||||
# lower order starts after higher order+1s
|
||||
self.assertEqual(len(bill_records), 3)
|
||||
self.assertEqual(int(bill.sum), 35)
|
||||
|
||||
self.assertEqual(bills[0].sum, price)
|
||||
|
||||
# expeted result:
|
||||
# 1x 5 chf bill record
|
||||
# 1x 5 chf bill record
|
||||
# 1x 10 partial bill record
|
||||
# Expected bill sum & records:
|
||||
# 2019-03-03 - 2019-04-02 +30d: 10
|
||||
# 2019-04-02 - 2019-04-17: +15d: 5
|
||||
# 2019-04-17 - 2019-05-17: +30d: 20
|
||||
# total: 35
|
||||
|
||||
|
||||
# def test_bill_for_increasing_product(self):
|
||||
# """
|
||||
# Modify a product, see one pro rata entry
|
||||
# """
|
||||
|
||||
# # Create product
|
||||
# starting_date = timezone.make_aware(datetime.datetime(2019,3,3))
|
||||
# starting_price = 30.5
|
||||
# product = SampleRecurringProduct.objects.create(owner=self.user,
|
||||
# rc_price=starting_price)
|
||||
# product.create_order(starting_date)
|
||||
|
||||
# recurring_period = product.default_recurring_period.value
|
||||
|
||||
# # First change
|
||||
# change1_date = timezone.make_aware(datetime.datetime(2019,4,17))
|
||||
# product.rc_price = 49.5
|
||||
# product.save()
|
||||
# product.create_or_update_recurring_order(when_to_start=change1_date)
|
||||
|
||||
# # Second change
|
||||
# change2_date = timezone.make_aware(datetime.datetime(2019,5,8))
|
||||
# product.rc_price = 56.5
|
||||
# product.save()
|
||||
# product.create_or_update_recurring_order(when_to_start=change2_date)
|
||||
|
||||
# # Create bill one month after 2nd change
|
||||
# bill_ending_date = timezone.make_aware(datetime.datetime(2019,6,30))
|
||||
# bills = Bill.create_next_bills_for_user(self.user,
|
||||
# ending_date=bill_ending_date)
|
||||
|
||||
# # only one bill in this test case
|
||||
# bill = bills[0]
|
||||
|
||||
# expected_amount = starting_price
|
||||
|
||||
# d2 = starting_date + recurring_period
|
||||
# duration2 = change1_date - d2
|
||||
|
||||
# expected_amount = 0
|
||||
|
||||
# # Expected bill sum & records:
|
||||
# # 2019-03-03 - 2019-04-02 +30d: 30.5
|
||||
# # 2019-04-02 - 2019-04-17: +15d: 15.25
|
||||
# # 2019-04-17 - 2019-05-08: +21d: (21/30) * 49.5
|
||||
# # 2019-05-08 - 2019-06-07: +30d: 56.5
|
||||
# # 2019-06-07 - 2019-07-07: +30d: 56.5
|
||||
|
||||
|
||||
# self.assertEqual(bills[0].sum, price)
|
||||
|
||||
# # 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