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


Python BillingAccount.get_account_by_domain方法代码示例

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


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

示例1: email_enterprise_report

# 需要导入模块: from corehq.apps.accounting.models import BillingAccount [as 别名]
# 或者: from corehq.apps.accounting.models.BillingAccount import get_account_by_domain [as 别名]
def email_enterprise_report(domain, slug, couch_user):
    account = BillingAccount.get_account_by_domain(domain)
    report = EnterpriseReport.create(slug, account.id, couch_user)

    # Generate file
    csv_file = io.StringIO()
    writer = csv.writer(csv_file)
    writer.writerow(report.headers)
    writer.writerows(report.rows)

    # Store file in redis
    hash_id = uuid.uuid4().hex
    redis = get_redis_client()
    redis.set(hash_id, csv_file.getvalue())
    redis.expire(hash_id, 60 * 60 * 24)
    csv_file.close()

    # Send email
    url = absolute_reverse("enterprise_dashboard_download", args=[domain, report.slug, str(hash_id)])
    link = "<a href='{}'>{}</a>".format(url, url)
    subject = _("Enterprise Dashboard: {}").format(report.title)
    body = "The enterprise report you requested for the account {} is ready.<br>" \
           "You can download the data at the following link: {}<br><br>" \
           "Please remember that this link will only be active for 24 hours.".format(account.name, link)
    send_html_email_async(subject, couch_user.username, body)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:27,代码来源:tasks.py

示例2: _get_account_or_404

# 需要导入模块: from corehq.apps.accounting.models import BillingAccount [as 别名]
# 或者: from corehq.apps.accounting.models.BillingAccount import get_account_by_domain [as 别名]
def _get_account_or_404(request, domain):
    account = BillingAccount.get_account_by_domain(domain)

    if account is None:
        raise Http404()

    if not account.has_enterprise_admin(request.couch_user.username):
        if not has_privilege(request, privileges.ACCOUNTING_ADMIN):
            raise Http404()

    return account
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:13,代码来源:views.py

示例3: can_add_extra_mobile_workers

# 需要导入模块: from corehq.apps.accounting.models import BillingAccount [as 别名]
# 或者: from corehq.apps.accounting.models.BillingAccount import get_account_by_domain [as 别名]
def can_add_extra_mobile_workers(request):
    from corehq.apps.users.models import CommCareUser
    from corehq.apps.accounting.models import BillingAccount
    num_web_users = CommCareUser.total_by_domain(request.domain)
    user_limit = request.plan.user_limit
    if user_limit == -1 or num_web_users < user_limit:
        return True
    if not has_privilege(request, privileges.ALLOW_EXCESS_USERS):
        account = BillingAccount.get_account_by_domain(request.domain)
        if account is None or account.date_confirmed_extra_charges is None:
            return False
    return True
开发者ID:johan--,项目名称:commcare-hq,代码行数:14,代码来源:util.py

示例4: domain_billing_context

# 需要导入模块: from corehq.apps.accounting.models import BillingAccount [as 别名]
# 或者: from corehq.apps.accounting.models.BillingAccount import get_account_by_domain [as 别名]
def domain_billing_context(request):
    is_domain_billing_admin = False
    restrict_domain_creation = settings.RESTRICT_DOMAIN_CREATION
    if getattr(request, 'couch_user', None) and getattr(request, 'domain', None):
        account = BillingAccount.get_account_by_domain(request.domain)
        if account:
            if has_privilege(request, privileges.ACCOUNTING_ADMIN):
                is_domain_billing_admin = True
            elif account.has_enterprise_admin(request.couch_user.username):
                is_domain_billing_admin = True
            if not is_domain_billing_admin:
                restrict_domain_creation = restrict_domain_creation or account.restrict_domain_creation
    return {
        'IS_DOMAIN_BILLING_ADMIN': is_domain_billing_admin,
        'restrict_domain_creation': restrict_domain_creation,
    }
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:18,代码来源:context_processors.py

示例5: process_request

# 需要导入模块: from corehq.apps.accounting.models import BillingAccount [as 别名]
# 或者: from corehq.apps.accounting.models.BillingAccount import get_account_by_domain [as 别名]
    def process_request(self, request):
        customer = None
        amount = self.get_charge_amount(request)
        card = request.POST.get('stripeToken')
        remove_card = request.POST.get('removeCard')
        is_saved_card = request.POST.get('selectedCardType') == 'saved'
        save_card = request.POST.get('saveCard') and not is_saved_card
        autopay = request.POST.get('autopayCard')
        billing_account = BillingAccount.get_account_by_domain(self.domain)
        generic_error = {
            'error': {
                'message': _(
                    "Something went wrong while processing your payment. "
                    "We're working quickly to resolve the issue. No charges "
                    "were issued. Please try again in a few hours."
                ),
            },
        }
        try:
            with transaction.atomic():
                if remove_card:
                    self.payment_method.remove_card(card)
                    return {'success': True, 'removedCard': card, }
                if save_card:
                    card = self.payment_method.create_card(card, billing_account, self.domain, autopay=autopay)
                if save_card or is_saved_card:
                    customer = self.payment_method.customer

                payment_record = PaymentRecord.create_record(
                    self.payment_method, 'temp', amount
                )
                self.update_credits(payment_record)

                charge = self.create_charge(amount, card=card, customer=customer)

            payment_record.transaction_id = charge.id
            payment_record.save()
            self.update_payment_information(billing_account)
        except stripe.error.CardError as e:
            # card was declined
            return e.json_body
        except (
            stripe.error.AuthenticationError,
            stripe.error.InvalidRequestError,
            stripe.error.APIConnectionError,
            stripe.error.StripeError,
        ) as e:
            log_accounting_error(
                "A payment for %(cost_item)s failed due "
                "to a Stripe %(error_class)s: %(error_msg)s" % {
                    'error_class': e.__class__.__name__,
                    'cost_item': self.cost_item_name,
                    'error_msg': e.json_body['error']
                }
            )
            return generic_error
        except Exception as e:
            log_accounting_error(
                "A payment for %(cost_item)s failed due to: %(error_msg)s" % {
                    'cost_item': self.cost_item_name,
                    'error_msg': e,
                }
            )
            return generic_error

        try:
            self.send_email(payment_record)
        except Exception:
            log_accounting_error(
                "Failed to send out an email receipt for "
                "payment related to PaymentRecord No. %s. "
                "Everything else succeeded."
                % payment_record.id
            )

        return {
            'success': True,
            'card': card,
            'wasSaved': save_card,
            'changedBalance': amount,
        }
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:83,代码来源:payment_handlers.py

示例6: request_new_domain

# 需要导入模块: from corehq.apps.accounting.models import BillingAccount [as 别名]
# 或者: from corehq.apps.accounting.models.BillingAccount import get_account_by_domain [as 别名]
def request_new_domain(request, form, is_new_user=True):
    now = datetime.utcnow()
    current_user = CouchUser.from_django_user(request.user, strict=True)

    dom_req = RegistrationRequest()
    if is_new_user:
        dom_req.request_time = now
        dom_req.request_ip = get_ip(request)
        dom_req.activation_guid = uuid.uuid1().hex

    project_name = form.cleaned_data.get('hr_name') or form.cleaned_data.get('project_name')
    name = name_to_url(project_name, "project")
    with CriticalSection(['request_domain_name_{}'.format(name)]):
        name = Domain.generate_name(name)
        new_domain = Domain(
            name=name,
            hr_name=project_name,
            is_active=False,
            date_created=datetime.utcnow(),
            creating_user=current_user.username,
            secure_submissions=True,
            use_sql_backend=True,
            first_domain_for_user=is_new_user
        )

        # Avoid projects created by dimagi.com staff members as self started
        new_domain.internal.self_started = not current_user.is_dimagi

        if form.cleaned_data.get('domain_timezone'):
            new_domain.default_timezone = form.cleaned_data['domain_timezone']

        if not is_new_user:
            new_domain.is_active = True

        # ensure no duplicate domain documents get created on cloudant
        new_domain.save(**get_safe_write_kwargs())

    if not new_domain.name:
        new_domain.name = new_domain._id
        new_domain.save()  # we need to get the name from the _id

    if is_new_user:
        # Only new-user domains are eligible for Advanced trial
        # domains with no subscription are equivalent to be on free Community plan
        create_30_day_advanced_trial(new_domain, current_user.username)
    else:
        ensure_explicit_community_subscription(
            new_domain.name, date.today(), SubscriptionAdjustmentMethod.USER,
            web_user=current_user.username,
        )

    UserRole.init_domain_with_presets(new_domain.name)

    # add user's email as contact email for billing account for the domain
    account = BillingAccount.get_account_by_domain(new_domain.name)
    billing_contact, _ = BillingContactInfo.objects.get_or_create(account=account)
    billing_contact.email_list = [current_user.email]
    billing_contact.save()

    dom_req.domain = new_domain.name

    if request.user.is_authenticated:
        if not current_user:
            current_user = WebUser()
            current_user.sync_from_django_user(request.user)
            current_user.save()
        current_user.add_domain_membership(new_domain.name, is_admin=True)
        current_user.save()
        dom_req.requesting_user_username = request.user.username
        dom_req.new_user_username = request.user.username

    if is_new_user:
        dom_req.save()
        if settings.IS_SAAS_ENVIRONMENT:
            from corehq.apps.app_manager.tasks import load_appcues_template_app
            chain(
                load_appcues_template_app.si(new_domain.name, current_user.username, HEALTH_APP),
                load_appcues_template_app.si(new_domain.name, current_user.username, AGG_APP),
                load_appcues_template_app.si(new_domain.name, current_user.username, WASH_APP),
                send_domain_registration_email.si(
                    request.user.email,
                    dom_req.domain,
                    dom_req.activation_guid,
                    request.user.get_full_name(),
                    request.user.first_name
                )
            ).apply_async()
        else:
            send_domain_registration_email(request.user.email,
                                           dom_req.domain,
                                           dom_req.activation_guid,
                                           request.user.get_full_name(),
                                           request.user.first_name)
    send_new_request_update_email(request.user, get_ip(request), new_domain.name, is_new_user=is_new_user)

    send_hubspot_form(HUBSPOT_CREATED_NEW_PROJECT_SPACE_FORM_ID, request)
    return new_domain.name
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:99,代码来源:utils.py

示例7: handle

# 需要导入模块: from corehq.apps.accounting.models import BillingAccount [as 别名]
# 或者: from corehq.apps.accounting.models.BillingAccount import get_account_by_domain [as 别名]
    def handle(self, *args, **options):
        if len(args) != 1:
            print "Invalid arguments: %s" % str(args)
            return

        completed = 0
        total = 0
        filename = args[0]
        with open(filename) as f:
            reader = csv.reader(f)
            reader.next()
            for row in reader:
                total = total + 1
                domain = row[0]
                plan_version, subscription = Subscription.get_subscribed_plan_by_domain(domain)
                if subscription is None:
                    print "Could not find Subscription for %s" % domain

                account = BillingAccount.get_account_by_domain(domain)
                if account is None:
                    print "Could not find BillingAccount for %s" % domain

                if account is not None and subscription is not None:
                    '''
                    service_type = self.normalize(row[1])  # self service, contracted, or not set
                    if service_type == "selfservice":
                        #print "%s service_type => SELF_SERVICE" % domain
                        subscription.service_type = SubscriptionType.SELF_SERVICE
                    elif service_type == "contracted":
                        #print "%s service_type => CONTRACTED" % domain
                        subscription.service_type = SubscriptionType.CONTRACTED
                    elif service_type == "notset":
                        #print "%s service_type => NOT_SET" % domain
                        subscription.service_type = SubscriptionType.NOT_SET
                    else:
                        pass
                        #print "Skipping service type for %s" % domain

                    entry_point = self.normalize(row[2])  # yes if self starter, might be missing
                    if entry_point == "yes":
                        #print "%s entry_point => SELF_STARTED" % domain
                        account.entry_point = EntryPoint.SELF_STARTED
                    elif entry_point == "no":
                        #print "%s entry_point => CONTRACTED" % domain
                        account.entry_point = EntryPoint.CONTRACTED
                    else:
                        #print "Skipping entry point for %s" % domain
                        pass
                    '''

                    pro_bono_status = self.normalize(row[3])  # yes/no
                    if pro_bono_status == "yes":
                        #print "%s pro_bono_status => YES" % domain
                        subscription.pro_bono_status = ProBonoStatus.YES
                    elif pro_bono_status == "discounted":
                        #print "%s pro_bono_status => DISCOUNTED" % domain
                        subscription.pro_bono_status = ProBonoStatus.DISCOUNTED
                    else:
                        #print "%s pro_bono_status => NO" % domain
                        subscription.pro_bono_status = ProBonoStatus.NO

                    '''print "setting %s's service_type=%s, entry_point=%s, pro_bono=%s" % (
                        domain, subscription.service_type, account.entry_point, subscription.pro_bono_status
                    )'''

                    subscription.save()
                    account.save()
                    completed = completed + 1

        print "Completed %i of %i domains" % (completed, total)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:72,代码来源:2015_05_29_update_subscriptions.py

示例8: handle

# 需要导入模块: from corehq.apps.accounting.models import BillingAccount [as 别名]
# 或者: from corehq.apps.accounting.models.BillingAccount import get_account_by_domain [as 别名]
    def handle(self, *args, **options):
        if raw_input(
            'Are you sure you want to re-bill all SMS billables with'
            ' gateway fees in INR calculated prior to March 1, 2016?\n'
            'This action will invalidate the old billables, create new ones,'
            ' and add the difference as general account credit to each'
            ' affected domain. \n[y/n]'
        ).lower() != 'y':
            raise CommandError('abort')

        inr = Currency.objects.filter(code="INR").first()

        affected_criteria = SmsBillable.objects.filter(
            gateway_fee__currency__code=inr.code,
            date_created__lt=datetime.date(2016, 3, 1),
            is_valid=True
        )
        for unique_b in affected_criteria.order_by('domain').distinct('domain'):
            all_affected_billables = affected_criteria.filter(
                domain=unique_b.domain,
            )
            total_affected = all_affected_billables.count()
            if total_affected > 0:
                print(
                    "\nUpdating {total_affected} billables for"
                    " domain {domain}".format(
                        domain=unique_b.domain,
                        total_affected=total_affected
                    )
                )
                stdout.write(">> BILLABLES: ")
            total_diff = Decimal('0.0')
            for billable in all_affected_billables.all():
                stdout.write('.')
                updated_billable = self._get_updated_billable(billable, inr)

                old_gateway_cost = (
                    billable.gateway_fee.amount /
                    billable.gateway_fee_conversion_rate
                )
                new_gateway_cost = (
                    updated_billable.gateway_fee.amount /
                    updated_billable.gateway_fee_conversion_rate
                )

                difference = old_gateway_cost - new_gateway_cost
                total_diff += difference * Decimal('1.0000')
                total_diff += difference * Decimal('1.0000')
            stdout.flush()
            if total_diff > Decimal('0.0'):
                print(
                    "\n!! >>> FOUND difference of {diff}, "
                    "applying General Credits to domain {domain}".format(
                        diff=round(total_diff, 4),
                        domain=unique_b.domain,
                    )
                )
                try:
                    affected_account = BillingAccount.get_account_by_domain(unique_b.domain)
                    CreditLine.add_credit(
                        total_diff,
                        affected_account,
                        note="Automated re-calc for UNICEL SMS Fees due to incorrect"
                             "conversion rate",
                        reason=CreditAdjustmentReason.MANUAL,
                    )
                    for b in all_affected_billables.all():
                        b.is_valid = False
                        b.save()
                except Exception as e:
                    print("Could not add credits to {domain} due to {error}".format(
                        domain=unique_b.domain,
                        error=e
                    ))
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:76,代码来源:retrobill_india_unicel_03012016.py

示例9: __init__

# 需要导入模块: from corehq.apps.accounting.models import BillingAccount [as 别名]
# 或者: from corehq.apps.accounting.models.BillingAccount import get_account_by_domain [as 别名]
 def __init__(self, payment_method, domain):
     self.payment_method = payment_method
     self.domain = domain
     self.account = BillingAccount.get_account_by_domain(self.domain)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:6,代码来源:payment_handlers.py


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