本文整理汇总了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),
)
])
示例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)
示例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))
示例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))
示例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
示例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'}],
)