Exemplo n.º 1
0
 def test_community_invoice(self):
     """
     For an unsubscribed domain with any charges over the community limit for the month of invoicing,
     make sure that an invoice is generated in addition to a subscription for that month to
     the community plan.
     """
     domain = generator.arbitrary_domain()
     generator.create_excess_community_users(domain)
     account = BillingAccount.get_or_create_account_by_domain(
         domain, created_by=self.dimagi_user)[0]
     billing_contact = generator.arbitrary_contact_info(account, self.dimagi_user)
     billing_contact.save()
     account.date_confirmed_extra_charges = datetime.date.today()
     account.save()
     tasks.generate_invoices()
     subscriber = Subscriber.objects.get(domain=domain.name)
     invoices = Invoice.objects.filter(subscription__subscriber=subscriber)
     self.assertEqual(invoices.count(), 1)
     invoice = invoices.get()
     self.assertEqual(invoice.subscription.subscriber.domain, domain.name)
     self.assertEqual(invoice.subscription.date_start, invoice.date_start)
     self.assertEqual(
         invoice.subscription.date_end - datetime.timedelta(days=1),
         invoice.date_end
     )
     domain.delete()
Exemplo n.º 2
0
    def test_community(self):
        """
        For Community plans (plan monthly fee is 0.0) that incur other rate charges, like users or SMS messages,
        make sure that the following is true:
        - base_description is None
        - unit_description is None
        - unit_cost is equal to 0
        - quantity is equal to 0
        - total and subtotal are 0.0
        """
        domain = generator.arbitrary_domain()
        generator.create_excess_community_users(domain)

        tasks.generate_invoices()
        subscriber = Subscriber.objects.get(domain=domain.name)
        invoice = Invoice.objects.filter(subscription__subscriber=subscriber).get()

        product_line_items = invoice.lineitem_set.filter(feature_rate__exact=None)
        self.assertEqual(product_line_items.count(), 1)
        product_line_item = product_line_items.get()
        self.assertIsNotNone(product_line_item.base_description)
        self.assertIsNone(product_line_item.unit_description)
        self.assertEqual(product_line_item.unit_cost, Decimal('0.0000'))
        self.assertEqual(product_line_item.quantity, 1)
        self.assertEqual(product_line_item.subtotal, Decimal('0.0000'))
        self.assertEqual(product_line_item.total, Decimal('0.0000'))

        domain.delete()
Exemplo n.º 3
0
    def test_community_over_limit(self):
        """
        For a domain under community (no subscription) with users over the community limit, make sure that:
        - base_description is None
        - base_cost is 0.0
        - unit_description is not None
        - unit_cost is equal to the per_excess_fee on the user rate
        - quantity is equal to number of commcare users in that domain minus the monthly_limit on the user rate
        - total and subtotals are equal to number of extra users * per_excess_fee
        """
        domain = generator.arbitrary_domain()
        num_active = generator.create_excess_community_users(domain)

        account = BillingAccount.get_or_create_account_by_domain(
            domain, created_by=self.dimagi_user)[0]
        billing_contact = generator.arbitrary_contact_info(account, self.dimagi_user)
        billing_contact.save()
        account.date_confirmed_extra_charges = datetime.date.today()
        account.save()

        tasks.generate_invoices()
        subscriber = Subscriber.objects.get(domain=domain.name)
        invoice = Invoice.objects.filter(subscription__subscriber=subscriber).get()
        user_line_item = invoice.lineitem_set.get_feature_by_type(FeatureType.USER).get()

        self.assertIsNone(user_line_item.base_description)
        self.assertEqual(user_line_item.base_cost, Decimal('0.0000'))

        num_to_charge = num_active - self.community_plan.user_limit
        self.assertIsNotNone(user_line_item.unit_description)
        self.assertEqual(user_line_item.quantity, num_to_charge)
        self.assertEqual(user_line_item.unit_cost, self.user_rate.per_excess_fee)
        self.assertEqual(user_line_item.subtotal, num_to_charge * self.user_rate.per_excess_fee)
        self.assertEqual(user_line_item.total, num_to_charge * self.user_rate.per_excess_fee)
        domain.delete()
Exemplo n.º 4
0
    def test_community_over_limit(self):
        """
        For a domain under community (no subscription) with users over the community limit, make sure that:
        - base_description is None
        - base_cost is 0.0
        - unit_description is not None
        - unit_cost is equal to the per_excess_fee on the user rate
        - quantity is equal to number of commcare users in that domain minus the monthly_limit on the user rate
        - total and subtotals are equal to number of extra users * per_excess_fee
        """
        domain = generator.arbitrary_domain()
        num_active = generator.create_excess_community_users(domain)

        tasks.generate_invoices()
        subscriber = Subscriber.objects.get(domain=domain.name)
        invoice = Invoice.objects.filter(subscription__subscriber=subscriber).get()
        user_line_item = invoice.lineitem_set.get_feature_by_type(FeatureType.USER).get()

        self.assertIsNone(user_line_item.base_description)
        self.assertEqual(user_line_item.base_cost, Decimal('0.0000'))

        num_to_charge = num_active - generator.MAX_COMMUNITY_USERS
        self.assertIsNotNone(user_line_item.unit_description)
        self.assertEqual(user_line_item.quantity, num_to_charge)
        self.assertEqual(user_line_item.unit_cost, self.user_rate.per_excess_fee)
        self.assertEqual(user_line_item.subtotal, num_to_charge * self.user_rate.per_excess_fee)
        self.assertEqual(user_line_item.total, num_to_charge * self.user_rate.per_excess_fee)
        domain.delete()
Exemplo n.º 5
0
    def test_product_plan_for_community_invoices(self):
        """
        Make sure that the different product domains get the different community plans by product type.
        """
        domains_by_product = generator.arbitrary_domains_by_product_type()
        for domain in domains_by_product.values():
            generator.create_excess_community_users(domain)

        tasks.generate_invoices()
        for product_type, domain in domains_by_product.items():
            subscriber = Subscriber.objects.get(domain=domain.name)
            self.assertEqual(subscriber.subscription_set.count(), 1)
            subscription = subscriber.subscription_set.get()
            self.assertEqual(subscription.invoice_set.count(), 1)
            expected_community_plan = DefaultProductPlan.objects.get(product_type=product_type)
            self.assertEqual(subscription.plan_version.plan, expected_community_plan.plan)
            domain.delete()
Exemplo n.º 6
0
    def test_community_invoice(self):
        """
        For an unsubscribed domain with any charges over the community limit for the month of invoicing,
        make sure that an invoice is generated in addition to a subscription for that month to
        the community plan.
        """
        domain = generator.arbitrary_domain()
        generator.create_excess_community_users(domain)

        tasks.generate_invoices()
        subscriber = Subscriber.objects.get(domain=domain.name)
        invoices = Invoice.objects.filter(subscription__subscriber=subscriber)
        self.assertEqual(invoices.count(), 1)
        invoice = invoices.get()
        self.assertEqual(invoice.subscription.subscriber.domain, domain.name)
        self.assertEqual(invoice.subscription.date_start, invoice.date_start)
        self.assertEqual(invoice.subscription.date_end, invoice.date_end)
        domain.delete()
Exemplo n.º 7
0
    def test_use_prev_billing_account_for_community_invoice(self):
        """
        Make sure that if a billing account was already auto generated for a previous community invoice,
        that a new one is not created.
        """
        domain = generator.arbitrary_domain()
        generator.create_excess_community_users(domain)

        second_invoicing_date = datetime.date.today()
        second_invoice_start, second_invoice_end = utils.get_previous_month_date_range(second_invoicing_date)
        first_invoicing_date = second_invoice_start - datetime.timedelta(days=random.randint(0, 365))

        tasks.generate_invoices(first_invoicing_date)
        tasks.generate_invoices(second_invoicing_date)
        subscriber = Subscriber.objects.get(domain=domain.name)
        invoices = Invoice.objects.filter(subscription__subscriber=subscriber)
        self.assertEqual(invoices.count(), 2)
        invoices = invoices.all()
        self.assertNotEqual(invoices[0].subscription, invoices[1].subscription)
        self.assertEqual(invoices[0].subscription.account, invoices[1].subscription.account)
        for invoice in invoices:
            self.assertEqual(invoice.subscription.subscriber.domain, domain.name)
        domain.delete()