当前位置: 首页>>代码示例>>Python>>正文


Python models.CreditLine类代码示例

本文整理汇总了Python中corehq.apps.accounting.models.CreditLine的典型用法代码示例。如果您正苦于以下问题:Python CreditLine类的具体用法?Python CreditLine怎么用?Python CreditLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CreditLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_credits_available_for_product_in_account

def get_credits_available_for_product_in_account(account):
    return sum([
        credit_line.balance for credit_line in itertools.chain(
            CreditLine.get_credits_for_account(account, is_product=True),
            CreditLine.get_credits_for_account(account),
        )
    ])
开发者ID:dimagi,项目名称:commcare-hq,代码行数:7,代码来源:mixins.py

示例2: _auto_generate_credits

 def _auto_generate_credits(self, line_item):
     CreditLine.add_credit(
         line_item.subtotal,
         subscription=self.subscription,
         product_type=self.rate.product.product_type,
         permit_inactive=True,
     )
开发者ID:sheelio,项目名称:commcare-hq,代码行数:7,代码来源:invoicing.py

示例3: test_subscription_level_sms_credits

    def test_subscription_level_sms_credits(self):
        # Add SMS usage
        arbitrary_sms_billables_for_domain(
            self.domain, self.sms_date, self.sms_rate.monthly_limit + 1
        )
        arbitrary_sms_billables_for_domain(
            self.domain2, self.sms_date, num_sms=self.advanced_rate.monthly_limit + 10
        )

        # Cover the cost of 1 SMS on the Standard subscription
        CreditLine.add_credit(
            amount=Decimal(0.7500),
            feature_type=FeatureType.SMS,
            subscription=self.subscription
        )
        # Cover the cost of 10 SMS on the Advanced subscription
        CreditLine.add_credit(
            amount=Decimal(7.5000),
            feature_type=FeatureType.SMS,
            subscription=self.sub2,
        )

        tasks.generate_invoices(self.invoice_date)
        self.assertEqual(CustomerInvoice.objects.count(), 1)
        invoice = CustomerInvoice.objects.first()
        self.assertEqual(invoice.balance, Decimal('1500.0000'))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:26,代码来源:test_customer_invoicing.py

示例4: test_transfer_credit_without_credit

    def test_transfer_credit_without_credit(self):
        original_credit_balance = 0
        CreditLine.add_credit(
            original_credit_balance,
            account=self.subscription.account,
            subscription=self.subscription,
        )
        original_balance = self.invoice.balance
        adjustment_amount = random.randint(1, 5)

        adjust_balance_form = AdjustBalanceForm(
            self.invoice,
            {
                'adjustment_type': 'credit',
                'custom_amount': adjustment_amount,
                'method': CreditAdjustmentReason.TRANSFER,
                'note': 'some text',
                'invoice_id': self.invoice.id,
            }
        )
        self.assertTrue(adjust_balance_form.is_valid())

        adjust_balance_form.adjust_balance()
        self.assertEqual(original_balance, self.invoice.balance)
        self.assertEqual(original_credit_balance, sum(
            credit_line.balance
            for credit_line in CreditLine.get_credits_for_invoice(self.invoice)
        ))
开发者ID:saakaifoundry,项目名称:commcare-hq,代码行数:28,代码来源:test_forms.py

示例5: _auto_generate_credits

 def _auto_generate_credits(self, line_item):
     CreditLine.add_credit(
         line_item.subtotal,
         subscription=self.subscription,
         product_type=SoftwareProductType.ANY,
         permit_inactive=True,
     )
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:7,代码来源:invoicing.py

示例6: update_credits

 def update_credits(self, payment_record):
     for feature in self.features:
         feature_amount = feature['amount']
         if feature_amount >= 0.5:
             self.credit_lines.append(CreditLine.add_credit(
                 feature_amount,
                 account=self.account,
                 subscription=self.subscription,
                 feature_type=feature['type'],
                 payment_record=payment_record,
             ))
         else:
             logger.error("[BILLING] {account} tried to make a payment for {feature} for less than $0.5."
                          "You should follow up with them.".format(account=self.account,
                                                                   feature=feature['type']))
     for product in self.products:
         plan_amount = product['amount']
         if plan_amount >= 0.5:
             self.credit_lines.append(CreditLine.add_credit(
                 plan_amount,
                 account=self.account,
                 subscription=self.subscription,
                 product_type=product['type'],
                 payment_record=payment_record,
             ))
         else:
             logger.error("[BILLING] {account} tried to make a payment for {product} for less than $0.5."
                          "You should follow up with them.".format(account=self.account,
                                                                   product=product['type']))
开发者ID:sheelio,项目名称:commcare-hq,代码行数:29,代码来源:payment_handlers.py

示例7: _generate_rate_credits_for_testing

    def _generate_rate_credits_for_testing(self, fee, rate_kwarg, generate_invoice_credit=True):
        """
        Generates enough line item credit for two invoicing periods.
        """
        rate_credit_by_account = CreditLine.add_rate_credit(
            fee,
            self.account,
            **rate_kwarg
        )
        self.assertEqual(CreditAdjustment.objects.filter(credit_line=rate_credit_by_account).count(), 1)

        rate_credit_by_subscription = CreditLine.add_rate_credit(
            fee,
            self.account,
            subscription=self.subscription,
            **rate_kwarg
        )
        self.assertEqual(CreditAdjustment.objects.filter(credit_line=rate_credit_by_subscription).count(), 1)

        if generate_invoice_credit:
            # this credit should not count toward the line item
            subscription_credit = CreditLine.add_subscription_credit(
                fee,
                self.subscription
            )
            self.assertEqual(CreditAdjustment.objects.filter(credit_line=subscription_credit).count(), 1)

        return rate_credit_by_account, rate_credit_by_subscription
开发者ID:dszafranek,项目名称:commcare-hq,代码行数:28,代码来源:test_credit_lines.py

示例8: test_combined_credits

    def test_combined_credits(self):
        """
        Test that line item credits get applied first to the line items
        and invoice credits get applied to the remaining balance.
        """
        user_rate_credit_by_account = CreditLine.add_credit(
            self.monthly_user_fee, account=self.account,
            feature_type=self.user_rate.feature.feature_type,
        )
        self.assertEqual(CreditAdjustment.objects.filter(
            credit_line=user_rate_credit_by_account).count(), 1
        )

        user_rate_credit_by_subscription = CreditLine.add_credit(
            self.monthly_user_fee,
            feature_type=self.user_rate.feature.feature_type,
            subscription=self.subscription
        )
        self.assertEqual(CreditAdjustment.objects.filter(
            credit_line=user_rate_credit_by_subscription
        ).count(), 1)

        subscription_credit, account_credit = self._generate_subscription_and_account_invoice_credits(
            self.product_rate.monthly_fee, self.subscription, self.account
        )

        self._test_final_invoice_balance()

        self._test_credit_use(subscription_credit)
        self._test_credit_use(user_rate_credit_by_subscription)
        self._test_credit_use(subscription_credit)
        self._test_credit_use(account_credit)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:32,代码来源:test_credit_lines.py

示例9: test_transfers

    def test_transfers(self):
        advanced_plan = DefaultProductPlan.get_default_plan_by_domain(self.domain, edition=SoftwarePlanEdition.ADVANCED)
        standard_plan = DefaultProductPlan.get_default_plan_by_domain(self.domain, edition=SoftwarePlanEdition.STANDARD)
        first_sub = Subscription.new_domain_subscription(self.account, self.domain, advanced_plan)

        product_credit = CreditLine.add_credit(
            self.product_credit_amt, subscription=first_sub, product_type=SoftwareProductType.COMMCARE
        )
        feature_credit = CreditLine.add_credit(
            self.feature_credit_amt, subscription=first_sub, feature_type=FeatureType.USER
        )
        subscription_credit = CreditLine.add_credit(self.subscription_credit_amt, subscription=first_sub)
        original_credits = [product_credit, feature_credit, subscription_credit]

        second_sub = first_sub.change_plan(standard_plan)

        second_credits = self._ensure_transfer(original_credits)
        for credit_line in second_credits:
            self.assertEqual(credit_line.subscription.pk, second_sub.pk)

        second_sub.date_end = datetime.date.today() + datetime.timedelta(days=5)
        second_sub.save()

        third_sub = second_sub.renew_subscription()
        third_credits = self._ensure_transfer(second_credits)
        for credit_line in third_credits:
            self.assertEqual(credit_line.subscription.pk, third_sub.pk)

        third_sub.cancel_subscription()
        account_credits = self._ensure_transfer(third_credits)
        for credit_line in account_credits:
            self.assertIsNone(credit_line.subscription)
            self.assertEqual(credit_line.account.pk, self.account.pk)
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:33,代码来源:test_credit_lines.py

示例10: _generate_subscription_and_account_invoice_credits

    def _generate_subscription_and_account_invoice_credits(self, monthly_fee, subscription, account):
        subscription_credit = CreditLine.add_credit(monthly_fee, subscription=subscription)
        self.assertEqual(CreditAdjustment.objects.filter(credit_line=subscription_credit).count(), 1)

        account_credit = CreditLine.add_credit(monthly_fee, account=account)
        self.assertEqual(CreditAdjustment.objects.filter(credit_line=account_credit).count(), 1)
        return subscription_credit, account_credit
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:7,代码来源:test_credit_lines.py

示例11: test_feature_line_item_credits

    def test_feature_line_item_credits(self):
        """
        Make sure that the feature line item Credit Lines are properly created and that the appropriate
        CreditAdjustments are being recorded. Also that available credit lines are being applied to the
        invoices properly.
        """
        rate_credit_by_account = CreditLine.add_credit(
            self.monthly_user_fee, account=self.account,
            feature_type=self.user_rate.feature.feature_type,
        )
        self.assertEqual(CreditAdjustment.objects.filter(
            credit_line=rate_credit_by_account).count(), 1
        )

        rate_credit_by_subscription = CreditLine.add_credit(
            self.monthly_user_fee,
            feature_type=self.user_rate.feature.feature_type,
            subscription=self.subscription
        )
        self.assertEqual(CreditAdjustment.objects.filter(
            credit_line=rate_credit_by_subscription
        ).count(), 1)

        subscription_credit = CreditLine.add_credit(
            self.monthly_user_fee, subscription=self.subscription
        )
        self.assertEqual(CreditAdjustment.objects.filter(
            credit_line=subscription_credit).count(), 1
        )

        self._test_line_item_crediting(
            lambda invoice: invoice.lineitem_set.get_feature_by_type(FeatureType.USER).get()
        )
        self._test_credit_use(rate_credit_by_account)
        self._test_credit_use(rate_credit_by_subscription)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:35,代码来源:test_credit_lines.py

示例12: test_get_credits_by_subscription_and_features_only_returns_active_credits

    def test_get_credits_by_subscription_and_features_only_returns_active_credits(self):
        # Add credits to subscription
        product_credit = self.add_product_credit(100.00)
        sms_credit = self.add_sms_credit(200.00)
        user_credit = self.add_user_credit(300.00)

        # Deactivate one credit
        sms_credit.is_active = False
        sms_credit.save()

        # Check that get_credits_by_subscription_and_features only returns active credit lines
        product_credits = CreditLine.get_credits_by_subscription_and_features(
            subscription=self.subscription, is_product=True
        )
        self.assertEqual(1, product_credits.count())
        self.assertEqual(product_credit, product_credits.first())

        user_credits = CreditLine.get_credits_by_subscription_and_features(
            subscription=self.subscription, feature_type=FeatureType.USER
        )
        self.assertEqual(1, user_credits.count())
        self.assertEqual(user_credit, user_credits.first())

        sms_credits = CreditLine.get_credits_by_subscription_and_features(
            subscription=self.subscription, feature_type=FeatureType.SMS
        )
        self.assertEqual(0, sms_credits.count())
开发者ID:dimagi,项目名称:commcare-hq,代码行数:27,代码来源:test_credit_lines.py

示例13: get_credits_available_for_product_in_subscription

def get_credits_available_for_product_in_subscription(current_subscription):
    return sum([
        credit_line.balance for credit_line in itertools.chain(
            CreditLine.get_credits_by_subscription_and_features(current_subscription, is_product=True),
            CreditLine.get_credits_by_subscription_and_features(current_subscription),
        )
    ])
开发者ID:dimagi,项目名称:commcare-hq,代码行数:7,代码来源:mixins.py

示例14: create_invoice_for_subscription

    def create_invoice_for_subscription(self, subscription):
        if subscription.is_trial:
            # Don't create invoices for trial subscriptions
            logger.info("[BILLING] Skipping invoicing for Subscription " "%s because it's a trial." % subscription.pk)
            return

        if subscription.auto_generate_credits:
            for product_rate in subscription.plan_version.product_rates.all():
                CreditLine.add_credit(
                    product_rate.monthly_fee, subscription=subscription, product_type=product_rate.product.product_type
                )

        days_until_due = DEFAULT_DAYS_UNTIL_DUE
        if subscription.date_delay_invoicing is not None:
            td = subscription.date_delay_invoicing - self.date_end
            days_until_due = max(days_until_due, td.days)
        date_due = self.date_end + datetime.timedelta(days_until_due)

        if subscription.date_start > self.date_start:
            invoice_start = subscription.date_start
        else:
            invoice_start = self.date_start

        if subscription.date_end is not None and subscription.date_end <= self.date_end:
            # Since the Subscription is actually terminated on date_end
            # have the invoice period be until the day before date_end.
            invoice_end = subscription.date_end - datetime.timedelta(days=1)
        else:
            invoice_end = self.date_end

        invoice = Invoice(
            subscription=subscription,
            date_start=invoice_start,
            date_end=invoice_end,
            date_due=date_due,
            is_hidden=subscription.do_not_invoice,
        )
        invoice.save()

        if subscription.subscriptionadjustment_set.count() == 0:
            # record that the subscription was created
            SubscriptionAdjustment.record_adjustment(
                subscription, method=SubscriptionAdjustmentMethod.TASK, invoice=invoice
            )

        self.generate_line_items(invoice, subscription)
        invoice.calculate_credit_adjustments()
        invoice.update_balance()
        invoice.save()

        record = BillingRecord.generate_record(invoice)
        try:
            record.send_email()
        except InvoiceEmailThrottledError as e:
            if not self.logged_throttle_error:
                logger.error("[BILLING] %s" % e)
                self.logged_throttle_error = True

        return invoice
开发者ID:hashimoto-hb,项目名称:commcare-hq,代码行数:59,代码来源:invoicing.py

示例15: add_feature_rate

 def add_feature_rate():
     CreditLine.add_rate_credit(
         amount,
         get_account_for_rate(),
         feature_rate=FeatureRate.objects.get(id=self.cleaned_data["feature_rate"]),
         subscription=subscription,
         note=note,
     )
开发者ID:pawelreise,项目名称:commcare-hq,代码行数:8,代码来源:forms.py


注:本文中的corehq.apps.accounting.models.CreditLine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。