From 83a0ca0e4ee032fe5ee5047062d9062c29a8d903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Fri, 17 Apr 2020 09:15:52 +0200 Subject: [PATCH] Adapt billing tests to product activation structure --- uncloud_django_based/uncloud/uncloud_pay/models.py | 6 +++++- uncloud_django_based/uncloud/uncloud_pay/tests.py | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/uncloud_django_based/uncloud/uncloud_pay/models.py b/uncloud_django_based/uncloud/uncloud_pay/models.py index b26621c..b213c35 100644 --- a/uncloud_django_based/uncloud/uncloud_pay/models.py +++ b/uncloud_django_based/uncloud/uncloud_pay/models.py @@ -481,7 +481,7 @@ class Order(models.Model): # Trigger initial bill generation at order creation. def save(self, *args, **kwargs): super(Order, self).save(*args, **kwargs) - Bill.generate_for(timezone.now().year, timezone.now().month, self.owner) + Bill.generate_for(self.starting_date.year, self.starting_date.month, self.owner) @property def records(self): @@ -496,6 +496,10 @@ class Order(models.Model): return reduce(lambda acc, record: acc + record.recurring_price, self.records, 0) # Used by uncloud_pay tests. + @property + def bills(self): + return Bill.objects.filter(order=self) + def add_record(self, one_time_price, recurring_price, description): OrderRecord.objects.create(order=self, one_time_price=one_time_price, diff --git a/uncloud_django_based/uncloud/uncloud_pay/tests.py b/uncloud_django_based/uncloud/uncloud_pay/tests.py index d441e75..f76007f 100644 --- a/uncloud_django_based/uncloud/uncloud_pay/tests.py +++ b/uncloud_django_based/uncloud/uncloud_pay/tests.py @@ -31,7 +31,7 @@ class BillingTestCase(TestCase): order.add_record(one_time_price, recurring_price, description) # Generate & check bill for first month: full recurring_price + setup. - first_month_bills = Bill.generate_for(2020, 3, self.user) + first_month_bills = order.bills # Initial bill generated at order creation. self.assertEqual(len(first_month_bills), 1) self.assertEqual(first_month_bills[0].total, one_time_price + recurring_price) @@ -65,7 +65,7 @@ class BillingTestCase(TestCase): order.add_record(one_time_price, recurring_price, description) # Generate & check bill for first year: recurring_price + setup. - first_year_bills = Bill.generate_for(2020, 3, self.user) + first_year_bills = order.bills # Initial bill generated at order creation. self.assertEqual(len(first_year_bills), 1) self.assertEqual(first_year_bills[0].starting_date.date(), date.fromisoformat('2020-03-31')) @@ -106,7 +106,7 @@ class BillingTestCase(TestCase): order.add_record(one_time_price, recurring_price, description) # Generate & check bill for first month: recurring_price + setup. - first_month_bills = Bill.generate_for(2020, 3, self.user) + first_month_bills = order.bills self.assertEqual(len(first_month_bills), 1) self.assertEqual(float(first_month_bills[0].total), round(16 * recurring_price, AMOUNT_DECIMALS) + one_time_price)