forked from uncloud/uncloud
Adapt billing tests to product activation structure
This commit is contained in:
parent
5d5bf486b5
commit
83a0ca0e4e
2 changed files with 8 additions and 4 deletions
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue