Exemplo n.º 1
0
    def setUp(self):
        super(TestBillingAutoPay, self).setUp()
        self.account.created_by_domain = self.domain
        self.account.save()

        self.currency = generator.init_default_currency()

        self.web_user = generator.arbitrary_web_user()
        self.dimagi_user = generator.arbitrary_web_user(is_dimagi=True)
        self.fake_card = FakeStripeCard()
        self.fake_stripe_customer = FakeStripeCustomer(cards=[self.fake_card])

        self.account.update_autopay_user(self.web_user.username, self.domain)
        self.invoice_date = utils.months_from_date(self.subscription.date_start,
                                                   random.randint(2, self.subscription_length))

        self.account_2 = generator.billing_account(self.dimagi_user, self.web_user)
        self.domain_2 = generator.arbitrary_domain()

        self.subscription_2, self.subscription_length_2 = generator.generate_domain_subscription_from_date(
            generator.get_start_date(), self.account_2, self.domain_2.name,
            min_num_months=self.min_subscription_length,
        )

        tasks.generate_invoices(self.invoice_date)
Exemplo n.º 2
0
    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_from_date(
            new_subscription_start, self.account, other_domain.name, min_num_months=self.min_subscription_length,
        )
        # other account credit that shouldn't count toward this invoice
        other_account = generator.billing_account(self.dimagi_user, generator.arbitrary_web_user())

        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)
        self._clean_credits()
    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_from_date(
            new_subscription_start,
            self.account,
            other_domain.name,
            min_num_months=self.min_subscription_length,
        )
        # other account credit that shouldn't count toward this invoice
        other_account = generator.billing_account(
            self.dimagi_user, generator.arbitrary_web_user())

        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)
        self._clean_credits()
Exemplo n.º 4
0
 def setUp(self):
     super(TestSubscription, 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.subscription, self.subscription_length = generator.generate_domain_subscription_from_date(
         datetime.date.today(), self.account, 'test'
     )
Exemplo n.º 5
0
 def setUp(self):
     super(TestSubscription, 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.subscription, self.subscription_length = generator.generate_domain_subscription_from_date(
         datetime.date.today(), self.account, 'test')
Exemplo n.º 6
0
    def setUp(self):
        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()

        generator.instantiate_subscribable_plans()
        generator.instantiate_community_plans()
        self.subscription, self.subscription_length = generator.generate_domain_subscription_from_date(
            generator.get_start_date(), self.account, self.domain.name, min_num_months=self.min_subscription_length,
        )
Exemplo n.º 7
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, self.subscription_length = generator.generate_domain_subscription_from_date(
            generator.get_start_date(), self.account, self.domain.name, min_num_months=self.min_subscription_length
        )
        self.community_plan = DefaultProductPlan.objects.get(
            product_type=SoftwareProductType.COMMCARE, edition=SoftwarePlanEdition.COMMUNITY
        ).plan.get_version()
Exemplo n.º 8
0
    def setUp(self):
        super(TestContractedInvoices, self).setUp()
        generator.delete_all_subscriptions()

        self.subscription, self.subscription_length = generator.generate_domain_subscription_from_date(
            generator.get_start_date(),
            self.account,
            self.domain.name,
            min_num_months=self.min_subscription_length,
            service_type=SubscriptionType.CONTRACTED,
        )

        self.invoice_date = utils.months_from_date(
            self.subscription.date_start, random.randint(2, self.subscription_length)
        )
Exemplo n.º 9
0
    def setUp(self):
        super(TestContractedInvoices, self).setUp()
        generator.delete_all_subscriptions()

        self.subscription, self.subscription_length = generator.generate_domain_subscription_from_date(
            generator.get_start_date(),
            self.account,
            self.domain.name,
            min_num_months=self.min_subscription_length,
            service_type=SubscriptionType.CONTRACTED,
        )

        self.invoice_date = utils.months_from_date(
            self.subscription.date_start,
            random.randint(2, self.subscription_length))
Exemplo n.º 10
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, self.subscription_length = generator.generate_domain_subscription_from_date(
            generator.get_start_date(),
            self.account,
            self.domain.name,
            min_num_months=self.min_subscription_length,
        )
        self.community_plan = DefaultProductPlan.objects.get(
            product_type=SoftwareProductType.COMMCARE,
            edition=SoftwarePlanEdition.COMMUNITY).plan.get_version()
Exemplo n.º 11
0
 def setUp(self):
     super(TestBillingRecord, self).setUp()
     self.billing_contact = generator.arbitrary_web_user()
     self.dimagi_user = generator.arbitrary_web_user(is_dimagi=True)
     self.domain = Domain(name='test')
     self.domain.save()
     self.invoice_start, self.invoice_end = get_previous_month_date_range()
     self.currency = generator.init_default_currency()
     self.account = generator.billing_account(self.dimagi_user, self.billing_contact)
     self.subscription, self.subscription_length = generator.generate_domain_subscription_from_date(
         datetime.date.today(), self.account, self.domain.name
     )
     self.invoice = Invoice(
         subscription=self.subscription,
         date_start=self.invoice_start,
         date_end=self.invoice_end,
         is_hidden=False,
     )
     self.billing_record = BillingRecord(invoice=self.invoice)
Exemplo n.º 12
0
    def test_date_due_set_large_invoice(self):
        """Date Due only gets set for a large invoice (> $100)"""
        Subscription.objects.all().delete()
        subscription_length = 5  # months
        plan = DefaultProductPlan.objects.get(
            edition=SoftwarePlanEdition.ADVANCED, product_type=SoftwareProductType.COMMCARE, is_trial=False
        ).plan.get_version()
        subscription, _ = generator.generate_domain_subscription_from_date(
            generator.get_start_date(),
            self.account,
            self.domain.name,
            subscription_length=subscription_length,
            plan_version=plan,
        )

        invoice_date_large = utils.months_from_date(subscription.date_start, 3)
        tasks.generate_invoices(invoice_date_large)
        large_invoice = subscription.invoice_set.last()

        self.assertTrue(large_invoice.balance > SMALL_INVOICE_THRESHOLD)
        self.assertIsNotNone(large_invoice.date_due)
Exemplo n.º 13
0
    def test_date_due_not_set_small_invoice(self):
        """Date Due doesn't get set if the invoice is small"""
        Subscription.objects.all().delete()
        subscription_length = 5  # months
        plan = DefaultProductPlan.objects.get(
            edition=SoftwarePlanEdition.STANDARD, product_type=SoftwareProductType.COMMCARE, is_trial=False
        ).plan.get_version()
        subscription, _ = generator.generate_domain_subscription_from_date(
            generator.get_start_date(),
            self.account,
            self.domain.name,
            subscription_length=subscription_length,
            plan_version=plan,
        )

        invoice_date_small = utils.months_from_date(subscription.date_start, 1)
        tasks.generate_invoices(invoice_date_small)
        small_invoice = subscription.invoice_set.first()

        self.assertTrue(small_invoice.balance <= SMALL_INVOICE_THRESHOLD)
        self.assertIsNone(small_invoice.date_due)
Exemplo n.º 14
0
    def test_date_due_gets_set_autopay(self):
        """Date due always gets set for autopay """
        Subscription.objects.all().delete()
        subscription_length = 4
        plan = DefaultProductPlan.objects.get(
            edition=SoftwarePlanEdition.STANDARD, product_type=SoftwareProductType.COMMCARE, is_trial=False
        ).plan.get_version()
        autopay_subscription, _ = generator.generate_domain_subscription_from_date(
            generator.get_start_date(),
            self.account,
            self.domain.name,
            subscription_length=subscription_length,
            plan_version=plan,
        )

        autopay_subscription.account.update_autopay_user(self.billing_contact.username, self.domain)
        invoice_date_autopay = utils.months_from_date(autopay_subscription.date_start, 1)
        tasks.generate_invoices(invoice_date_autopay)

        autopay_invoice = autopay_subscription.invoice_set.last()
        self.assertTrue(autopay_invoice.balance <= SMALL_INVOICE_THRESHOLD)
        self.assertIsNotNone(autopay_invoice.date_due)