def setUpClass(cls):
        super(BaseCustomerInvoiceCase, cls).setUpClass()

        if cls.is_using_test_plans:
            generator.bootstrap_test_software_plan_versions()

        cls.billing_contact = generator.create_arbitrary_web_user_name()
        cls.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True)
        cls.account = generator.billing_account(
            cls.dimagi_user, cls.billing_contact)
        cls.domain = generator.arbitrary_domain()
        cls.account.is_customer_billing_account = True
        cls.account.save()

        cls.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED)
        cls.advanced_plan.plan.is_customer_software_plan = True

        cls.subscription_length = 15  # months
        subscription_start_date = datetime.date(2016, 2, 23)
        subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length)
        cls.subscription = generator.generate_domain_subscription(
            cls.account,
            cls.domain,
            date_start=subscription_start_date,
            date_end=subscription_end_date,
        )

        advanced_subscription_end_date = add_months_to_date(subscription_end_date, 2)
        cls.domain2 = generator.arbitrary_domain()
        cls.sub2 = generator.generate_domain_subscription(
            cls.account,
            cls.domain2,
            date_start=subscription_start_date,
            date_end=advanced_subscription_end_date,
            plan_version=cls.advanced_plan
        )

        cls.domain3 = generator.arbitrary_domain()
        cls.sub3 = generator.generate_domain_subscription(
            cls.account,
            cls.domain3,
            date_start=subscription_start_date,
            date_end=advanced_subscription_end_date,
            plan_version=cls.advanced_plan
        )

        # This subscription should not be included in any customer invoices in these tests
        cls.domain_community = generator.arbitrary_domain()
        cls.sub3 = generator.generate_domain_subscription(
            cls.account,
            cls.domain3,
            date_start=subscription_start_date,
            date_end=advanced_subscription_end_date,
            plan_version=DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.COMMUNITY)
        )
Beispiel #2
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()
    def test_invoice_credit(self):
        """
        Make sure that subscription and account level credits get applied to the invoice balance appropriately.
        """
        invoice_monthly_total = self.product_rate.monthly_fee + self.monthly_user_fee

        subscription_credit, account_credit = self._generate_subscription_and_account_invoice_credits(
            invoice_monthly_total, self.subscription, self.account
        )

        # other subscription credit that shouldn't count toward this invoice
        other_domain = generator.arbitrary_domain()
        # so that the other subscription doesn't draw from the same account credits, have it start 4 months later
        new_subscription_start = utils.months_from_date(self.subscription.date_start, 4)

        other_subscription = generator.generate_domain_subscription(
            self.account,
            other_domain,
            date_start=new_subscription_start,
            date_end=add_months_to_date(new_subscription_start, self.min_subscription_length),
        )

        # other account credit that shouldn't count toward this invoice
        other_account = generator.billing_account(self.dimagi_user, generator.create_arbitrary_web_user_name())

        self._generate_subscription_and_account_invoice_credits(
            invoice_monthly_total, other_subscription, other_account
        )

        self._test_final_invoice_balance()

        self._test_credit_use(subscription_credit)
        self._test_credit_use(account_credit)
        other_domain.delete()
Beispiel #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)

        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()
    def setUpClass(cls):
        super(BaseCustomerInvoiceCase, cls).setUpClass()

        cls.billing_contact = generator.create_arbitrary_web_user_name()
        cls.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True)
        cls.account = generator.billing_account(
            cls.dimagi_user, cls.billing_contact)
        cls.domain = generator.arbitrary_domain()
        cls.account.is_customer_billing_account = True
        cls.account.save()

        cls.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED)
        cls.advanced_plan.plan.is_customer_software_plan = True

        cls.subscription_length = 15  # months
        subscription_start_date = datetime.date(2016, 2, 23)
        subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length)
        cls.subscription = generator.generate_domain_subscription(
            cls.account,
            cls.domain,
            date_start=subscription_start_date,
            date_end=subscription_end_date,
        )
        cls.subscription.plan_version.plan.is_customer_software_plan = True

        advanced_subscription_end_date = add_months_to_date(subscription_end_date, 2)
        cls.domain2 = generator.arbitrary_domain()
        cls.sub2 = generator.generate_domain_subscription(
            cls.account,
            cls.domain2,
            date_start=subscription_start_date,
            date_end=advanced_subscription_end_date,
            plan_version=cls.advanced_plan
        )
        cls.sub2.plan_version.plan.is_customer_software_plan = True

        cls.domain3 = generator.arbitrary_domain()
        cls.sub3 = generator.generate_domain_subscription(
            cls.account,
            cls.domain3,
            date_start=subscription_start_date,
            date_end=advanced_subscription_end_date,
            plan_version=cls.advanced_plan
        )
        cls.sub3.plan_version.plan.is_customer_software_plan = True
 def setUp(self):
     super(TestCreditTransfers, self).setUp()
     self.product_credit_amt = Decimal('500.00')
     self.feature_credit_amt = Decimal('200.00')
     self.subscription_credit_amt = Decimal('600.00')
     self.domain = generator.arbitrary_domain()
     self.account = BillingAccount.get_or_create_account_by_domain(
         self.domain, created_by="*****@*****.**",
     )[0]
Beispiel #7
0
 def test_community_no_charges_no_invoice(self):
     """
     No invoices should be generated for domains that are not on a subscription and do not
     have any per_excess charges on users or SMS messages
     """
     domain = generator.arbitrary_domain()
     tasks.generate_invoices()
     self.assertRaises(Invoice.DoesNotExist,
                       lambda: Invoice.objects.get(subscription__subscriber__domain=domain.name))
     domain.delete()
Beispiel #8
0
 def test_community_no_charges_no_invoice(self):
     """
     No invoices should be generated for domains that are not on a subscription and do not
     have any per_excess charges on users or SMS messages
     """
     domain = generator.arbitrary_domain()
     tasks.generate_invoices()
     self.assertRaises(Invoice.DoesNotExist,
                       lambda: Invoice.objects.get(subscription__subscriber__domain=domain.name))
     domain.delete()
 def setUp(self):
     super(TestCreditTransfers, self).setUp()
     self.product_credit_amt = Decimal('500.00')
     self.feature_credit_amt = Decimal('200.00')
     self.subscription_credit_amt = Decimal('600.00')
     self.domain = generator.arbitrary_domain()
     self.account = BillingAccount.get_or_create_account_by_domain(
         self.domain,
         created_by="*****@*****.**",
     )[0]
 def setUpClass(cls):
     super(TestCreditTransfers, cls).setUpClass()
     cls.product_credit_amt = Decimal('500.00')
     cls.feature_credit_amt = Decimal('200.00')
     cls.subscription_credit_amt = Decimal('600.00')
     cls.domain = generator.arbitrary_domain()
     cls.account = BillingAccount.get_or_create_account_by_domain(
         cls.domain, created_by="*****@*****.**",
     )[0]
     cls.web_user_name = generator.create_arbitrary_web_user_name()
     cls.other_account = generator.billing_account(cls.web_user_name, cls.web_user_name)
Beispiel #11
0
 def setUpClass(cls):
     super(TestCreditTransfers, cls).setUpClass()
     cls.product_credit_amt = Decimal('500.00')
     cls.feature_credit_amt = Decimal('200.00')
     cls.subscription_credit_amt = Decimal('600.00')
     cls.domain = generator.arbitrary_domain()
     cls.account = BillingAccount.get_or_create_account_by_domain(
         cls.domain, created_by="*****@*****.**",
     )[0]
     cls.web_user_name = generator.create_arbitrary_web_user_name()
     cls.other_account = generator.billing_account(cls.web_user_name, cls.web_user_name)
Beispiel #12
0
 def setUp(self):
     super(TestCreditTransfers, self).setUp()
     self.product_credit_amt = Decimal('500.00')
     self.feature_credit_amt = Decimal('200.00')
     self.subscription_credit_amt = Decimal('600.00')
     self.domain = generator.arbitrary_domain()
     self.account = BillingAccount.get_or_create_account_by_domain(
         self.domain, created_by="*****@*****.**",
     )[0]
     self.web_user = generator.arbitrary_web_user()
     # TODO - refactor interface to generator.billing_account so web user object is not required
     self.other_account = generator.billing_account(self.web_user, self.web_user)
    def setUpClass(cls):
        super(TestUserSubscriptionChangeTransfers, cls).setUpClass()

        generator.bootstrap_test_software_plan_versions()
        generator.init_default_currency()

        cls.billing_contact = generator.create_arbitrary_web_user_name()
        cls.domain = generator.arbitrary_domain()
        cls.account = BillingAccount.get_or_create_account_by_domain(
            cls.domain, created_by=cls.billing_contact,
        )[0]
        generator.arbitrary_contact_info(cls.account, cls.billing_contact)
def _generate_invoice_and_subscription(days_ago, is_customer_billing_account=False):
    """
    :param days_ago: The number of days ago an invoice should be due
    :return: random domain, with invoices generated on the backend
    """
    invoice_due_date = datetime.date.today() - datetime.timedelta(days=days_ago)

    billing_contact = generator.create_arbitrary_web_user_name()
    dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True)
    account = generator.billing_account(
        dimagi_user,
        billing_contact
    )
    account.is_customer_billing_account = is_customer_billing_account
    account.save()

    domain = generator.arbitrary_domain()
    subscription_start_date = utils.months_from_date(invoice_due_date, -2)

    subscription = generator.generate_domain_subscription(
        account,
        domain,
        date_start=subscription_start_date,
        date_end=None,
        plan_version=DefaultProductPlan.get_default_plan_version(
            SoftwarePlanEdition.ADVANCED
        ),
        service_type=SubscriptionType.PRODUCT,
    )
    subscription.is_active = True
    subscription.save()

    invoice_date = utils.months_from_date(invoice_due_date, -1)
    DomainUserHistory.objects.create(
        domain=domain.name,
        num_users=20,
        record_date=invoice_date - datetime.timedelta(days=1)
    )
    tasks.generate_invoices(invoice_date)

    # for testing purposes, force the latest invoice due_date to be
    # the "invoice_due_date" specified above
    if is_customer_billing_account:
        latest_invoice = CustomerInvoice.objects.filter(
            account=account,
        ).latest('date_created')
    else:
        latest_invoice = subscription.invoice_set.latest('date_created')
    latest_invoice.date_due = invoice_due_date
    latest_invoice.save()

    return domain, latest_invoice
 def test_should_not_invoice_trial(self):
     trial_domain = generator.arbitrary_domain()
     subscription = Subscription.new_domain_subscription(
         self.account, trial_domain.name, self.advanced_plan, date_start=self.invoice_start
     )
     subscription.is_trial = True
     self.assertFalse(should_create_invoice(
         subscription=subscription,
         domain=subscription.subscriber.domain,
         invoice_start=self.invoice_start,
         invoice_end=self.invoice_end
     ))
     trial_domain.delete()
 def test_should_not_invoice_trial(self):
     trial_domain = generator.arbitrary_domain()
     subscription = Subscription.new_domain_subscription(
         self.account, trial_domain.name, self.advanced_plan, date_start=self.invoice_start
     )
     subscription.is_trial = True
     self.assertFalse(should_create_invoice(
         subscription=subscription,
         domain=subscription.subscriber.domain,
         invoice_start=self.invoice_start,
         invoice_end=self.invoice_end
     ))
     trial_domain.delete()
 def test_should_not_invoice_without_subscription_charges(self):
     feature_charge_domain = generator.arbitrary_domain()
     subscription = Subscription.new_domain_subscription(
         self.account, feature_charge_domain.name, self.advanced_plan, date_start=self.invoice_start
     )
     subscription.skip_invoicing_if_no_feature_charges = True
     self.assertFalse(should_create_invoice(
         subscription=subscription,
         domain=subscription.subscriber.domain,
         invoice_start=self.invoice_start,
         invoice_end=self.invoice_end
     ))
     feature_charge_domain.delete()
 def test_should_not_invoice_without_subscription_charges(self):
     feature_charge_domain = generator.arbitrary_domain()
     subscription = Subscription.new_domain_subscription(
         self.account, feature_charge_domain.name, self.advanced_plan, date_start=self.invoice_start
     )
     subscription.skip_invoicing_if_no_feature_charges = True
     self.assertFalse(should_create_invoice(
         subscription=subscription,
         domain=subscription.subscriber.domain,
         invoice_start=self.invoice_start,
         invoice_end=self.invoice_end
     ))
     feature_charge_domain.delete()
Beispiel #19
0
 def setUp(self):
     super(TestCreditTransfers, self).setUp()
     self.product_credit_amt = Decimal('500.00')
     self.feature_credit_amt = Decimal('200.00')
     self.subscription_credit_amt = Decimal('600.00')
     self.domain = generator.arbitrary_domain()
     self.account = BillingAccount.get_or_create_account_by_domain(
         self.domain,
         created_by="*****@*****.**",
     )[0]
     self.web_user = generator.arbitrary_web_user()
     # TODO - refactor interface to generator.billing_account so web user object is not required
     self.other_account = generator.billing_account(self.web_user,
                                                    self.web_user)
Beispiel #20
0
 def setUp(self):
     super(TestExportUtils, self).setUp()
     self.domain = generator.arbitrary_domain()
     self.account, _ = BillingAccount.get_or_create_account_by_domain(
         self.domain.name, created_by='*****@*****.**')
     self.account.save()
     subscription = Subscription.new_domain_subscription(
         self.account,
         self.domain.name,
         DefaultProductPlan.get_default_plan_version(
             edition=SoftwarePlanEdition.COMMUNITY),
         date_start=date.today() - timedelta(days=3))
     subscription.is_active = True
     subscription.save()
Beispiel #21
0
    def setUp(self):
        super(TestDomainInvoiceFactory, self).setUp()
        self.invoice_start, self.invoice_end = get_previous_month_date_range()

        self.domain = generator.arbitrary_domain()
        self.account = BillingAccount.get_or_create_account_by_domain(
            domain=self.domain.name, created_by="TEST")[0]
        self.community = DefaultProductPlan.get_default_plan_version()
        generator.arbitrary_commcare_users_for_domain(
            self.domain.name, self.community.user_limit + 1)

        self.invoice_factory = DomainInvoiceFactory(self.invoice_start,
                                                    self.invoice_end,
                                                    self.domain)
Beispiel #22
0
 def _generate_non_autopayable_entities(self):
     """
     Create account, domain, and subscription linked to the autopay user, but that don't have autopay enabled
     """
     self.non_autopay_account = generator.billing_account(
         web_user_creator=generator.arbitrary_web_user(is_dimagi=True),
         web_user_contact=self.autopay_user
     )
     self.non_autopay_domain = generator.arbitrary_domain()
     # Non-autopay subscription has same parameters as the autopayable subscription
     self.non_autopay_subscription = generator.generate_domain_subscription(
         self.non_autopay_account,
         self.non_autopay_domain,
         date_start=self.subscription.date_start,
         date_end=add_months_to_date(self.subscription.date_start, self.subscription_length),
     )
    def setUp(self):
        super(TestDomainInvoiceFactory, self).setUp()
        self.invoice_start, self.invoice_end = get_previous_month_date_range()

        self.domain = generator.arbitrary_domain()
        self.account = BillingAccount.get_or_create_account_by_domain(
            domain=self.domain.name, created_by="TEST"
        )[0]
        self.community = DefaultProductPlan.get_default_plan().plan.get_version()
        generator.arbitrary_commcare_users_for_domain(
            self.domain.name, self.community.user_limit + 1
        )

        self.invoice_factory = DomainInvoiceFactory(
            self.invoice_start, self.invoice_end, self.domain
        )
Beispiel #24
0
 def _generate_non_autopayable_entities(self):
     """
     Create account, domain, and subscription linked to the autopay user, but that don't have autopay enabled
     """
     self.non_autopay_account = generator.billing_account(
         web_user_creator=generator.arbitrary_web_user(is_dimagi=True),
         web_user_contact=self.autopay_user)
     self.non_autopay_domain = generator.arbitrary_domain()
     # Non-autopay subscription has same parameters as the autopayable subscription
     self.non_autopay_subscription = generator.generate_domain_subscription(
         self.non_autopay_account,
         self.non_autopay_domain,
         date_start=self.subscription.date_start,
         date_end=add_months_to_date(self.subscription.date_start,
                                     self.subscription_length),
     )
Beispiel #25
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()
        self.addCleanup(domain.delete)
        num_active = generator.create_excess_community_users(domain)

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

        calculate_users_in_all_domains(
            datetime.date(today.year, today.month, 1))
        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'))

        community_plan = DefaultProductPlan.get_default_plan_version()
        num_to_charge = num_active - 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)
Beispiel #26
0
    def setUpClass(cls):
        super(BaseInvoiceTestCase, cls).setUpClass()
        generator.bootstrap_test_plans()  # TODO - only call for subclasses that actually need the test plans
        cls.billing_contact = generator.create_arbitrary_web_user_name()
        cls.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True)
        cls.currency = generator.init_default_currency()
        cls.account = generator.billing_account(
            cls.dimagi_user, cls.billing_contact)
        cls.domain = generator.arbitrary_domain()

        cls.subscription_length = 15  # months
        subscription_start_date = datetime.date(2016, 2, 23)
        subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length)
        cls.subscription = generator.generate_domain_subscription(
            cls.account,
            cls.domain,
            date_start=subscription_start_date,
            date_end=subscription_end_date,
        )
    def test_deleted_domain_in_multiple_subscription_invoice(self):
        invoice_date = utils.months_from_date(self.subscription.date_start, 2)

        domain_to_be_deleted = generator.arbitrary_domain()
        generator.generate_domain_subscription(self.account,
                                               domain_to_be_deleted,
                                               date_start=self.sub2.date_start,
                                               date_end=self.sub2.date_end,
                                               plan_version=self.advanced_plan)
        domain_to_be_deleted.delete(leave_tombstone=True)

        calculate_users_in_all_domains(invoice_date)
        tasks.generate_invoices(invoice_date)

        self.assertEqual(CustomerInvoice.objects.count(), 1)
        invoice = CustomerInvoice.objects.first()

        num_product_line_items = invoice.lineitem_set.get_products().count()
        self.assertEqual(num_product_line_items, 2)
Beispiel #28
0
    def setUp(self):
        super(BaseInvoiceTestCase, self).setUp()
        self.billing_contact = generator.arbitrary_web_user()
        self.dimagi_user = generator.arbitrary_web_user(is_dimagi=True)
        self.currency = generator.init_default_currency()
        self.account = generator.billing_account(
            self.dimagi_user, self.billing_contact)
        self.domain = generator.arbitrary_domain()

        self.subscription_length = 15  # months
        subscription_start_date = datetime.date(2016, 2, 23)
        subscription_end_date = add_months_to_date(subscription_start_date, self.subscription_length)
        self.subscription = generator.generate_domain_subscription(
            self.account,
            self.domain,
            date_start=subscription_start_date,
            date_end=subscription_end_date,
        )

        self.community_plan = DefaultProductPlan.get_default_plan_version()
Beispiel #29
0
    def setUp(self):
        super(BaseInvoiceTestCase, self).setUp()
        self.billing_contact = generator.arbitrary_web_user()
        self.dimagi_user = generator.arbitrary_web_user(is_dimagi=True)
        self.currency = generator.init_default_currency()
        self.account = generator.billing_account(
            self.dimagi_user, self.billing_contact)
        self.domain = generator.arbitrary_domain()

        self.subscription_length = 15  # months
        subscription_start_date = datetime.date(2016, 2, 23)
        subscription_end_date = add_months_to_date(subscription_start_date, self.subscription_length)
        self.subscription = generator.generate_domain_subscription(
            self.account,
            self.domain,
            date_start=subscription_start_date,
            date_end=subscription_end_date,
        )

        self.community_plan = DefaultProductPlan.get_default_plan_version()
Beispiel #30
0
 def test_should_not_invoice_paused_plan(self):
     """
     Ensure that paused plans do not generate a CustomerInvoice
     """
     paused_domain = generator.arbitrary_domain()
     self.addCleanup(paused_domain.delete)
     paused_plan = generator.subscribable_plan_version(
         edition=SoftwarePlanEdition.PAUSED)
     paused_plan.plan.is_customer_software_plan = True
     subscription = Subscription.new_domain_subscription(
         self.account,
         paused_domain.name,
         paused_plan,
         date_start=self.invoice_start,
     )
     self.assertFalse(
         should_create_invoice(subscription=subscription,
                               domain=subscription.subscriber.domain,
                               invoice_start=self.invoice_start,
                               invoice_end=self.invoice_end))
Beispiel #31
0
    def setUpClass(cls):
        super(BaseInvoiceTestCase, cls).setUpClass()

        if cls.is_using_test_plans:
            generator.bootstrap_test_software_plan_versions()

        cls.billing_contact = generator.create_arbitrary_web_user_name()
        cls.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True)
        cls.currency = generator.init_default_currency()
        cls.account = generator.billing_account(
            cls.dimagi_user, cls.billing_contact)
        cls.domain = generator.arbitrary_domain()

        cls.subscription_length = 15  # months
        subscription_start_date = datetime.date(2016, 2, 23)
        subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length)
        cls.subscription = generator.generate_domain_subscription(
            cls.account,
            cls.domain,
            date_start=subscription_start_date,
            date_end=subscription_end_date,
        )
Beispiel #32
0
    def setUpClass(cls):
        super(BaseInvoiceTestCase, cls).setUpClass()

        if cls.is_using_test_plans:
            generator.bootstrap_test_software_plan_versions()

        cls.billing_contact = generator.create_arbitrary_web_user_name()
        cls.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True)
        cls.currency = generator.init_default_currency()
        cls.account = generator.billing_account(
            cls.dimagi_user, cls.billing_contact)
        cls.domain = generator.arbitrary_domain()

        cls.subscription_length = 15  # months
        subscription_start_date = datetime.date(2016, 2, 23)
        subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length)
        cls.subscription = generator.generate_domain_subscription(
            cls.account,
            cls.domain,
            date_start=subscription_start_date,
            date_end=subscription_end_date,
        )
    def setUp(self):
        super(TestInvoicingMethods, self).setUp()
        self.invoice_start = datetime.date(2018, 5, 1)
        self.invoice_end = datetime.date(2018, 5, 31)

        self.domain = generator.arbitrary_domain()
        self.account = BillingAccount.get_or_create_account_by_domain(
            domain=self.domain, created_by="TEST"
        )[0]
        self.account.is_customer_billing_account = True
        self.account.save()
        self.invoice_factory = CustomerAccountInvoiceFactory(self.invoice_start, self.invoice_end, self.account)
        self.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED)
        self.advanced_plan.plan.is_customer_software_plan = True
        self.pro_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.PRO)
        self.pro_plan.plan.is_customer_software_plan = True
        self.subscription = Subscription.new_domain_subscription(
            self.account,
            self.domain.name,
            self.advanced_plan,
            date_start=self.invoice_start,
            date_end=self.invoice_end
        )
    def setUp(self):
        super(TestInvoicingMethods, self).setUp()
        self.invoice_start = datetime.date(2018, 5, 1)
        self.invoice_end = datetime.date(2018, 5, 31)

        self.domain = generator.arbitrary_domain()
        self.account = BillingAccount.get_or_create_account_by_domain(
            domain=self.domain, created_by="TEST"
        )[0]
        self.account.is_customer_billing_account = True
        self.account.save()
        self.invoice_factory = CustomerAccountInvoiceFactory(self.invoice_start, self.invoice_end, self.account)
        self.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED)
        self.advanced_plan.plan.is_customer_software_plan = True
        self.pro_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.PRO)
        self.pro_plan.plan.is_customer_software_plan = True
        self.subscription = Subscription.new_domain_subscription(
            self.account,
            self.domain.name,
            self.advanced_plan,
            date_start=self.invoice_start,
            date_end=self.invoice_end
        )
Beispiel #35
0
 def _generate_non_autopayable_entities(cls):
     """
     Create account, domain, and subscription linked to the autopay user, but that don't have autopay enabled
     """
     cls.non_autopay_account = generator.billing_account(
         web_user_creator=generator.create_arbitrary_web_user_name(is_dimagi=True),
         web_user_contact=cls.autopay_user_email
     )
     cls.non_autopay_domain = generator.arbitrary_domain()
     # Non-autopay subscription has same parameters as the autopayable subscription
     cheap_plan = SoftwarePlan.objects.create(name='cheap')
     cheap_product_rate = SoftwareProductRate.objects.create(monthly_fee=100, name=cheap_plan.name)
     cheap_plan_version = SoftwarePlanVersion.objects.create(
         plan=cheap_plan,
         product_rate=cheap_product_rate,
         role=Role.objects.first(),
     )
     cls.non_autopay_subscription = generator.generate_domain_subscription(
         cls.non_autopay_account,
         cls.non_autopay_domain,
         plan_version=cheap_plan_version,
         date_start=cls.subscription.date_start,
         date_end=add_months_to_date(cls.subscription.date_start, cls.subscription_length),
     )
 def test_feature_charges(self):
     domain_under_limits = generator.arbitrary_domain()
     self.assertTrue(self.community.feature_charges_exist_for_domain(self.domain))
     self.assertFalse(self.community.feature_charges_exist_for_domain(domain_under_limits))
Beispiel #37
0
 def test_feature_charges(self):
     domain_under_limits = generator.arbitrary_domain()
     self.assertTrue(self.community.feature_charges_exist_for_domain(self.domain))
     self.assertFalse(self.community.feature_charges_exist_for_domain(domain_under_limits))
     domain_under_limits.delete()