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


Python CreditLine.get_credits_by_subscription_and_features方法代码示例

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


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

示例1: get_credits_available_for_product_in_subscription

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_by_subscription_and_features [as 别名]
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,代码行数:9,代码来源:mixins.py

示例2: test_get_credits_by_subscription_and_features_only_returns_active_credits

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_by_subscription_and_features [as 别名]
    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,代码行数:29,代码来源:test_credit_lines.py

示例3: add_user_credit

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_by_subscription_and_features [as 别名]
 def add_user_credit(self, amount):
     user_credit = CreditLine.add_credit(amount, subscription=self.subscription, feature_type=FeatureType.USER)
     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())
     return user_credit
开发者ID:dimagi,项目名称:commcare-hq,代码行数:10,代码来源:test_credit_lines.py

示例4: add_sms_credit

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_by_subscription_and_features [as 别名]
 def add_sms_credit(self, amount):
     sms_credit = CreditLine.add_credit(amount, subscription=self.subscription, feature_type=FeatureType.SMS)
     sms_credits = CreditLine.get_credits_by_subscription_and_features(
         subscription=self.subscription, feature_type=FeatureType.SMS
     )
     self.assertEqual(1, sms_credits.count())
     self.assertEqual(sms_credit, sms_credits.first())
     return sms_credit
开发者ID:dimagi,项目名称:commcare-hq,代码行数:10,代码来源:test_credit_lines.py

示例5: add_product_credit

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_by_subscription_and_features [as 别名]
 def add_product_credit(self, amount):
     product_credit = CreditLine.add_credit(amount, subscription=self.subscription, is_product=True)
     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())
     return product_credit
开发者ID:dimagi,项目名称:commcare-hq,代码行数:10,代码来源:test_credit_lines.py

示例6: test_active_subscription_credits_transferred_to_account

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_by_subscription_and_features [as 别名]
    def test_active_subscription_credits_transferred_to_account(self):
        credit_amount = random.randint(1, 10)
        CreditLine.add_credit(
            credit_amount,
            feature_type=FeatureType.SMS,
            subscription=self.current_subscription,
        )

        self.domain.delete()

        subscription_credits = CreditLine.get_credits_by_subscription_and_features(
            self.current_subscription,
            feature_type=FeatureType.SMS,
        )
        self.assertEqual(len(subscription_credits), 1)
        self.assertEqual(subscription_credits[0].balance, Decimal('0.0000'))
        account_credits = CreditLine.get_credits_for_account(
            self.current_subscription.account,
            feature_type=FeatureType.SMS,
        )
        self.assertEqual(len(account_credits), 1)
        self.assertEqual(account_credits[0].balance, Decimal(credit_amount))
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:24,代码来源:test_delete_domain.py

示例7: test_active_subscription_credits_transferred_to_account

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_by_subscription_and_features [as 别名]
    def test_active_subscription_credits_transferred_to_account(self):
        credit_amount = random.randint(1, 10)
        CreditLine.add_credit(
            credit_amount,
            feature_type=FeatureType.SMS,
            subscription=self.current_subscription,
        )

        self.domain.delete()

        # Check that get_credits_by_subscription_and_features does not return the old deactivated credit line
        subscription_credits = CreditLine.get_credits_by_subscription_and_features(
            self.current_subscription,
            feature_type=FeatureType.SMS,
        )
        self.assertEqual(len(subscription_credits), 0)

        # Check that old credit line has been tranferred to accoun
        account_credits = CreditLine.get_credits_for_account(
            self.current_subscription.account,
            feature_type=FeatureType.SMS,
        )
        self.assertEqual(len(account_credits), 1)
        self.assertEqual(account_credits[0].balance, Decimal(credit_amount))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:26,代码来源:test_delete_domain.py

示例8: send_prepaid_credits_export

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_by_subscription_and_features [as 别名]
def send_prepaid_credits_export():
    if settings.ENTERPRISE_MODE:
        return

    headers = [
        'Account Name', 'Project Space', 'Edition', 'Start Date', 'End Date',
        '# General Credits', '# Product Credits', '# User Credits', '# SMS Credits', 'Last Date Modified'
    ]

    body = []
    for subscription in Subscription.visible_objects.filter(
        service_type=SubscriptionType.PRODUCT,
    ).order_by('subscriber__domain', 'id'):
        general_credit_lines = CreditLine.get_credits_by_subscription_and_features(subscription)
        product_credit_lines = CreditLine.get_credits_by_subscription_and_features(subscription, is_product=True)
        user_credit_lines = CreditLine.get_credits_by_subscription_and_features(
            subscription, feature_type=FeatureType.USER)
        sms_credit_lines = CreditLine.get_credits_by_subscription_and_features(
            subscription, feature_type=FeatureType.SMS)
        all_credit_lines = general_credit_lines | product_credit_lines | user_credit_lines | sms_credit_lines

        body.append([
            subscription.account.name, subscription.subscriber.domain, subscription.plan_version.plan.edition,
            subscription.date_start, subscription.date_end,
            sum(credit_line.balance for credit_line in general_credit_lines),
            sum(credit_line.balance for credit_line in product_credit_lines),
            sum(credit_line.balance for credit_line in user_credit_lines),
            sum(credit_line.balance for credit_line in sms_credit_lines),
            max(
                credit_line.last_modified for credit_line in all_credit_lines
            ).strftime(SERVER_DATETIME_FORMAT_NO_SEC)
            if all_credit_lines else 'N/A',
        ])

    for account in BillingAccount.objects.order_by('name', 'id'):
        general_credit_lines = CreditLine.get_credits_for_account(account)
        product_credit_lines = CreditLine.get_credits_for_account(account, is_product=True)
        user_credit_lines = CreditLine.get_credits_for_account(account, feature_type=FeatureType.USER)
        sms_credit_lines = CreditLine.get_credits_for_account(account, feature_type=FeatureType.SMS)
        all_credit_lines = general_credit_lines | product_credit_lines | user_credit_lines | sms_credit_lines

        body.append([
            account.name, '', '', '', '',
            sum(credit_line.balance for credit_line in general_credit_lines),
            sum(credit_line.balance for credit_line in product_credit_lines),
            sum(credit_line.balance for credit_line in user_credit_lines),
            sum(credit_line.balance for credit_line in sms_credit_lines),
            max(
                credit_line.last_modified for credit_line in all_credit_lines
            ).strftime(SERVER_DATETIME_FORMAT_NO_SEC)
            if all_credit_lines else 'N/A',
        ])

    file_obj = io.StringIO()
    writer = csv.writer(file_obj)
    writer.writerow(headers)
    for row in body:
        writer.writerow([
            val if isinstance(val, six.text_type) else bytes(val)
            for val in row
        ])

    date_string = datetime.datetime.utcnow().strftime(SERVER_DATE_FORMAT)
    filename = 'prepaid-credits-export_%s_%s.csv' % (settings.SERVER_ENVIRONMENT, date_string)
    send_HTML_email(
        '[%s] Prepaid Credits Export - %s' % (settings.SERVER_ENVIRONMENT, date_string),
        settings.ACCOUNTS_EMAIL,
        'See attached file.',
        file_attachments=[{'file_obj': file_obj, 'title': filename, 'mimetype': 'text/csv'}],
    )
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:72,代码来源:tasks.py


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