Compute VAT rate and amount on bill generation

This commit is contained in:
fnux 2020-04-18 11:43:55 +02:00
commit b3afad5d5d
3 changed files with 54 additions and 38 deletions

View file

@ -37,18 +37,18 @@ class BillingTestCase(TestCase):
# Generate & check bill for first month: full recurring_price + setup.
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)
self.assertEqual(first_month_bills[0].amount, one_time_price + recurring_price)
# Generate & check bill for second month: full recurring_price.
second_month_bills = Bill.generate_for(2020, 4, self.user)
self.assertEqual(len(second_month_bills), 1)
self.assertEqual(second_month_bills[0].total, recurring_price)
self.assertEqual(second_month_bills[0].amount, recurring_price)
# Generate & check bill for third and last month: partial recurring_price.
third_month_bills = Bill.generate_for(2020, 5, self.user)
self.assertEqual(len(third_month_bills), 1)
# 31 days in May.
self.assertEqual(float(third_month_bills[0].total),
self.assertEqual(float(third_month_bills[0].amount),
round((7/31) * recurring_price, AMOUNT_DECIMALS))
# Check that running Bill.generate_for() twice does not create duplicates.
@ -76,7 +76,7 @@ class BillingTestCase(TestCase):
date.fromisoformat('2020-03-31'))
self.assertEqual(first_year_bills[0].ending_date.date(),
date.fromisoformat('2021-03-30'))
self.assertEqual(first_year_bills[0].total,
self.assertEqual(first_year_bills[0].amount,
recurring_price + one_time_price)
# Generate & check bill for second year: recurring_price.
@ -86,7 +86,7 @@ class BillingTestCase(TestCase):
date.fromisoformat('2021-03-31'))
self.assertEqual(second_year_bills[0].ending_date.date(),
date.fromisoformat('2022-03-30'))
self.assertEqual(second_year_bills[0].total, recurring_price)
self.assertEqual(second_year_bills[0].amount, recurring_price)
# Check that running Bill.generate_for() twice does not create duplicates.
self.assertEqual(len(Bill.generate_for(2020, 3, self.user)), 0)
@ -114,13 +114,13 @@ class BillingTestCase(TestCase):
# Generate & check bill for first month: recurring_price + setup.
first_month_bills = order.bills
self.assertEqual(len(first_month_bills), 1)
self.assertEqual(float(first_month_bills[0].total),
self.assertEqual(float(first_month_bills[0].amount),
round(16 * recurring_price, AMOUNT_DECIMALS) + one_time_price)
# Generate & check bill for first month: recurring_price.
second_month_bills = Bill.generate_for(2020, 4, self.user)
self.assertEqual(len(second_month_bills), 1)
self.assertEqual(float(second_month_bills[0].total),
self.assertEqual(float(second_month_bills[0].amount),
round(12 * recurring_price, AMOUNT_DECIMALS))
class ProductActivationTestCase(TestCase):
@ -159,7 +159,7 @@ class ProductActivationTestCase(TestCase):
self.assertEqual(product.status, UncloudStatus.AWAITING_PAYMENT)
# Pay initial bill, check that product is activated.
amount = product.order.bills[0].total
amount = product.order.bills[0].amount
payment = Payment(owner=self.user, amount=amount)
payment.save()
self.assertEqual(