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


Python CreditLine.get_credits_for_account方法代码示例

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


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

示例1: get_credits_available_for_product_in_account

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

示例2: test_get_credits_for_account_only_returns_active_credit

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_for_account [as 别名]
    def test_get_credits_for_account_only_returns_active_credit(self):
        account_credit = self.add_account_credit(100.00)

        # Deactivate credit line
        account_credit.is_active = False
        account_credit.save()

        # Check that get_credits_for_account does not return deactivated credit line
        self.assertEqual(CreditLine.get_credits_for_account(self.account).count(), 0)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:11,代码来源:test_credit_lines.py

示例3: test_active_subscription_credits_transferred_to_account

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_for_account [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

示例4: test_active_subscription_credits_transferred_to_account

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_for_account [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

示例5: add_account_credit

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_for_account [as 别名]
 def add_account_credit(self, amount):
     account_credit = CreditLine.add_credit(amount, account=self.account)
     self.assertEqual(CreditLine.get_credits_for_account(self.account).count(), 1)
     self.assertEqual(account_credit, CreditLine.get_credits_for_account(self.account).first())
     return account_credit
开发者ID:dimagi,项目名称:commcare-hq,代码行数:7,代码来源:test_credit_lines.py

示例6: send_prepaid_credits_export

# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import get_credits_for_account [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_for_account方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。