forked from uncloud/uncloud
Split bills between orders of the same billing address
This commit is contained in:
parent
db9ff5d18b
commit
3a03717b12
2 changed files with 100 additions and 25 deletions
|
|
@ -143,7 +143,6 @@ class ProductActivationTestCase(TestCase):
|
|||
starting_date=starting_date,
|
||||
recurring_period=RecurringPeriod.PER_MONTH,
|
||||
billing_address=self.billing_address)
|
||||
order.save()
|
||||
|
||||
product = GenericServiceProduct(
|
||||
custom_description="Test product",
|
||||
|
|
@ -154,7 +153,7 @@ class ProductActivationTestCase(TestCase):
|
|||
product.save()
|
||||
|
||||
# XXX: to be automated.
|
||||
order.add_record(product.one_time_price, product.recurring_price(), product.description)
|
||||
order.add_record(product.one_time_price, product.recurring_price, product.description)
|
||||
|
||||
# Validate initial state: must be awaiting payment.
|
||||
self.assertEqual(product.status, UncloudStatus.AWAITING_PAYMENT)
|
||||
|
|
@ -167,3 +166,63 @@ class ProductActivationTestCase(TestCase):
|
|||
GenericServiceProduct.objects.get(uuid=product.uuid).status,
|
||||
UncloudStatus.PENDING
|
||||
)
|
||||
|
||||
class BillingAddressTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.user = get_user_model().objects.create(
|
||||
username='jdoe',
|
||||
email='john.doe@domain.tld')
|
||||
|
||||
self.billing_address_01 = BillingAddress.objects.create(
|
||||
owner=self.user,
|
||||
street="unknown1",
|
||||
city="unknown1",
|
||||
postal_code="unknown1",
|
||||
country="CH")
|
||||
|
||||
self.billing_address_02 = BillingAddress.objects.create(
|
||||
owner=self.user,
|
||||
street="unknown2",
|
||||
city="unknown2",
|
||||
postal_code="unknown2",
|
||||
country="CH")
|
||||
|
||||
def test_billing_with_single_address(self):
|
||||
# Create new orders somewhere in the past so that we do not encounter
|
||||
# auto-created initial bills.
|
||||
starting_date = datetime.fromisoformat('2020-03-01')
|
||||
|
||||
order_01 = Order.objects.create(
|
||||
owner=self.user,
|
||||
starting_date=starting_date,
|
||||
recurring_period=RecurringPeriod.PER_MONTH,
|
||||
billing_address=self.billing_address_01)
|
||||
order_02 = Order.objects.create(
|
||||
owner=self.user,
|
||||
starting_date=starting_date,
|
||||
recurring_period=RecurringPeriod.PER_MONTH,
|
||||
billing_address=self.billing_address_01)
|
||||
|
||||
# We need a single bill since we work with a single address.
|
||||
bills = Bill.generate_for(2020, 4, self.user)
|
||||
self.assertEqual(len(bills), 1)
|
||||
|
||||
def test_billing_with_multiple_addresses(self):
|
||||
# Create new orders somewhere in the past so that we do not encounter
|
||||
# auto-created initial bills.
|
||||
starting_date = datetime.fromisoformat('2020-03-01')
|
||||
|
||||
order_01 = Order.objects.create(
|
||||
owner=self.user,
|
||||
starting_date=starting_date,
|
||||
recurring_period=RecurringPeriod.PER_MONTH,
|
||||
billing_address=self.billing_address_01)
|
||||
order_02 = Order.objects.create(
|
||||
owner=self.user,
|
||||
starting_date=starting_date,
|
||||
recurring_period=RecurringPeriod.PER_MONTH,
|
||||
billing_address=self.billing_address_02)
|
||||
|
||||
# We need different bills since we work with different addresses.
|
||||
bills = Bill.generate_for(2020, 4, self.user)
|
||||
self.assertEqual(len(bills), 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue