本文整理汇总了Python中corehq.apps.accounting.models.CreditLine.add_credit方法的典型用法代码示例。如果您正苦于以下问题:Python CreditLine.add_credit方法的具体用法?Python CreditLine.add_credit怎么用?Python CreditLine.add_credit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.accounting.models.CreditLine
的用法示例。
在下文中一共展示了CreditLine.add_credit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_combined_credits
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
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)
示例2: test_transfer_credit_without_credit
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
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)
))
示例3: _auto_generate_credits
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
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,
)
示例4: update_credits
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
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']))
示例5: test_feature_line_item_credits
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
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)
示例6: _auto_generate_credits
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
def _auto_generate_credits(self, line_item):
CreditLine.add_credit(
line_item.subtotal,
subscription=self.subscription,
product_type=SoftwareProductType.ANY,
permit_inactive=True,
)
示例7: test_transfers
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
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)
示例8: _generate_subscription_and_account_invoice_credits
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
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
示例9: test_subscription_level_sms_credits
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
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'))
示例10: create_invoice_for_subscription
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
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
示例11: test_transfers
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
def test_transfers(self):
advanced_plan = DefaultProductPlan.get_default_plan_version(
edition=SoftwarePlanEdition.ADVANCED
)
standard_plan = DefaultProductPlan.get_default_plan_version(
edition=SoftwarePlanEdition.STANDARD
)
first_sub = Subscription.new_domain_subscription(
self.account, self.domain.name, advanced_plan,
date_start=datetime.date.today() - relativedelta(days=1),
)
product_credit = CreditLine.add_credit(
self.product_credit_amt, subscription=first_sub,
is_product=True,
)
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()
deactivate_subscriptions(second_sub.date_end)
third_sub = Subscription.visible_objects.get(id=third_sub.id)
third_credits = self._ensure_transfer(second_credits)
for credit_line in third_credits:
self.assertEqual(credit_line.subscription.pk, third_sub.pk)
third_sub.date_end = third_sub.date_start + relativedelta(days=1)
third_sub.save()
Subscription.new_domain_subscription(
self.other_account, self.domain, DefaultProductPlan.get_default_plan_version(),
date_start=third_sub.date_end,
)
deactivate_subscriptions(third_sub.date_end)
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)
示例12: test_balance_adjustment
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
def test_balance_adjustment(self):
"""
Makes sure that the balance is added to the same invoice and same line item credit.
"""
product_credit = CreditLine.add_credit(
self.product_rate.monthly_fee, account=self.account, product_type=self.product_rate.product.product_type
)
self.assertEqual(CreditAdjustment.objects.filter(credit_line=product_credit).count(), 1)
CreditLine.add_credit(
self.product_rate.monthly_fee, account=self.account, product_type=self.product_rate.product.product_type
)
self.assertEqual(CreditAdjustment.objects.filter(credit_line=product_credit).count(), 2)
current_product_credit = CreditLine.objects.get(id=product_credit.id)
self.assertEqual(current_product_credit.balance, self.product_rate.monthly_fee * 2)
subscription_credit = CreditLine.add_credit(self.monthly_user_fee, subscription=self.subscription)
self.assertEqual(CreditAdjustment.objects.filter(credit_line=subscription_credit).count(), 1)
CreditLine.add_credit(self.monthly_user_fee, subscription=self.subscription)
self.assertEqual(CreditAdjustment.objects.filter(credit_line=subscription_credit).count(), 2)
current_subscription_credit = CreditLine.objects.get(id=subscription_credit.id)
self.assertEqual(current_subscription_credit.balance, self.monthly_user_fee * 2)
account_credit = CreditLine.add_credit(self.product_rate.monthly_fee, account=self.account)
self.assertEqual(CreditAdjustment.objects.filter(credit_line=account_credit).count(), 1)
CreditLine.add_credit(self.monthly_user_fee, account=self.account)
self.assertEqual(CreditAdjustment.objects.filter(credit_line=account_credit).count(), 2)
current_account_credit = CreditLine.objects.get(id=account_credit.id)
self.assertEqual(current_account_credit.balance, self.product_rate.monthly_fee + self.monthly_user_fee)
示例13: update_credits
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
def update_credits(self, payment_record):
# record the credit to the account
CreditLine.add_credit(
payment_record.amount, account=self.invoice.subscription.account,
payment_record=payment_record,
)
CreditLine.add_credit(
-payment_record.amount,
account=self.invoice.subscription.account,
invoice=self.invoice,
)
self.invoice.update_balance()
self.invoice.save()
示例14: test_account_level_product_credits
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [as 别名]
def test_account_level_product_credits(self):
CreditLine.add_credit(
amount=self.subscription.plan_version.product_rate.monthly_fee / 2,
account=self.account,
is_product=True
)
invoice_date = utils.months_from_date(self.subscription.date_start,
random.randint(2, self.subscription_length))
tasks.generate_invoices(invoice_date)
self.assertEqual(CustomerInvoice.objects.count(), 1)
invoice = CustomerInvoice.objects.first()
self.assertEqual(invoice.balance, Decimal('1350.0000'))
示例15: add_sms_credit
# 需要导入模块: from corehq.apps.accounting.models import CreditLine [as 别名]
# 或者: from corehq.apps.accounting.models.CreditLine import add_credit [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