示例#1
0
    def get_rate_response(self):
        gateway = self.data.get('gateway')
        try:
            backend_api_id = SQLMobileBackend.get_backend_api_id(gateway, is_couch_id=True)
        except Exception as e:
            log_smsbillables_error(
                "Failed to get backend for calculating an sms rate due to: %s"
                % e
            )
            raise SMSRateCalculatorError("Could not obtain connection information.")

        country_code = self.data.get('country_code')
        if country_code == NONMATCHING_COUNTRY:
            country_code = None
        direction = self.data.get('direction')

        gateway_fee = SmsGatewayFee.get_by_criteria(
            backend_api_id, direction, backend_instance=gateway,
            country_code=country_code,
        )
        usage_fee = SmsUsageFee.get_by_criteria(direction, self.request.domain)
        usd_gateway_fee = gateway_fee.amount / gateway_fee.currency.rate_to_default
        usd_total = usage_fee.amount + usd_gateway_fee

        return {
            'rate': _("%s per 160 character SMS") % fmt_dollar_amount(usd_total),
        }
    def get_rate_response(self):
        gateway = self.data.get('gateway')
        try:
            backend = SMSBackend.get(gateway)
            backend_api_id = get_backend_by_class_name(
                backend.doc_type).get_api_id()
        except Exception as e:
            logger.error("Failed to get backend for calculating an sms rate "
                         "due to: %s" % e)
            raise SMSRateCalculatorError(
                "Could not obtain connection information.")

        country_code = self.data.get('country_code')
        if country_code == NONMATCHING_COUNTRY:
            country_code = None
        direction = self.data.get('direction')

        gateway_fee = SmsGatewayFee.get_by_criteria(
            backend_api_id,
            direction,
            backend_instance=gateway,
            country_code=country_code,
        )
        usage_fee = SmsUsageFee.get_by_criteria(direction, self.request.domain)
        usd_gateway_fee = gateway_fee.amount * gateway_fee.currency.rate_to_default
        usd_total = usage_fee.amount + usd_gateway_fee

        return {
            'rate':
            _("%s per 160 character SMS") % fmt_dollar_amount(usd_total),
        }
示例#3
0
def arbitrary_sms_billables_for_domain(domain, message_month_date, num_sms, direction=None, multipart_count=1):
    from corehq.apps.smsbillables.models import SmsBillable, SmsGatewayFee, SmsUsageFee

    direction = direction or random.choice(DIRECTIONS)

    gateway_fee = SmsGatewayFee.create_new('MACH', direction, Decimal(0.5))
    usage_fee = SmsUsageFee.create_new(direction, Decimal(0.25))

    _, last_day_message = calendar.monthrange(message_month_date.year, message_month_date.month)

    billables = []
    for _ in range(0, num_sms):
        sms_billable = SmsBillable(
            gateway_fee=gateway_fee,
            usage_fee=usage_fee,
            log_id=data_gen.arbitrary_unique_name()[:50],
            phone_number=data_gen.random_phonenumber(),
            domain=domain,
            direction=direction,
            date_sent=datetime.date(message_month_date.year, message_month_date.month,
                                    random.randint(1, last_day_message)),
            multipart_count=multipart_count,
        )
        sms_billable.save()
        billables.append(sms_billable)
    return billables
示例#4
0
def arbitrary_sms_billables_for_domain(domain, direction, message_month_date,
                                       num_sms):
    from corehq.apps.smsbillables.models import SmsBillable, SmsGatewayFee, SmsUsageFee
    from corehq.apps.smsbillables import generator as sms_gen

    gateway_fee = SmsGatewayFee.create_new('MACH', direction,
                                           sms_gen.arbitrary_fee())
    usage_fee = SmsUsageFee.create_new(direction, sms_gen.arbitrary_fee())

    _, last_day_message = calendar.monthrange(message_month_date.year,
                                              message_month_date.month)

    for _ in range(0, num_sms):
        sms_billable = SmsBillable(
            gateway_fee=gateway_fee,
            usage_fee=usage_fee,
            log_id=data_gen.arbitrary_unique_name()[:50],
            phone_number=data_gen.random_phonenumber(),
            domain=domain,
            direction=direction,
            date_sent=datetime.date(message_month_date.year,
                                    message_month_date.month,
                                    random.randint(1, last_day_message)),
        )
        sms_billable.save()
示例#5
0
def arbitrary_sms_billables_for_domain(domain,
                                       message_month_date,
                                       num_sms,
                                       direction=None,
                                       multipart_count=1):
    direction = direction or random.choice(DIRECTIONS)

    gateway_fee = SmsGatewayFee.create_new('MACH', direction, Decimal(0.5))
    usage_fee = SmsUsageFee.create_new(direction, Decimal(0.25))

    _, last_day_message = calendar.monthrange(message_month_date.year,
                                              message_month_date.month)

    billables = []
    for _ in range(0, num_sms):
        sms_billable = SmsBillable(
            gateway_fee=gateway_fee,
            usage_fee=usage_fee,
            log_id=data_gen.arbitrary_unique_name()[:50],
            phone_number=data_gen.random_phonenumber(),
            domain=domain,
            direction=direction,
            date_sent=datetime.date(message_month_date.year,
                                    message_month_date.month,
                                    random.randint(1, last_day_message)),
            multipart_count=multipart_count,
        )
        sms_billable.save()
        billables.append(sms_billable)
    return billables
示例#6
0
 def _directed_fee(direction, backend_api_id, backend_instance_id):
     gateway_fee = SmsGatewayFee.get_by_criteria(
         backend_api_id, direction, backend_instance=backend_instance_id, country_code=country_code
     )
     if not gateway_fee or gateway_fee.amount is None:
         return None
     usd_gateway_fee = gateway_fee.amount / gateway_fee.currency.rate_to_default
     usage_fee = SmsUsageFee.get_by_criteria(direction)
     return fmt_dollar_amount(usage_fee.amount + usd_gateway_fee)
示例#7
0
 def _directed_fee(direction, backend_api_id, backend_instance_id):
     gateway_fee = SmsGatewayFee.get_by_criteria(
         backend_api_id,
         direction,
         backend_instance=backend_instance_id,
         country_code=country_code)
     if not gateway_fee or gateway_fee.amount is None:
         return None
     usd_gateway_fee = gateway_fee.amount / gateway_fee.currency.rate_to_default
     usage_fee = SmsUsageFee.get_by_criteria(direction)
     return fmt_dollar_amount(usage_fee.amount + usd_gateway_fee)
示例#8
0
def arbitrary_sms_billables_for_domain(domain, direction, message_month_date, num_sms):
    from corehq.apps.smsbillables.models import SmsBillable, SmsGatewayFee, SmsUsageFee
    from corehq.apps.smsbillables import generator as sms_gen

    gateway_fee = SmsGatewayFee.create_new('MACH', direction, sms_gen.arbitrary_fee())
    usage_fee = SmsUsageFee.create_new(direction, sms_gen.arbitrary_fee())

    _, last_day_message = calendar.monthrange(message_month_date.year, message_month_date.month)

    for _ in range(0, num_sms):
        sms_billable = SmsBillable(
            gateway_fee=gateway_fee,
            usage_fee=usage_fee,
            log_id=data_gen.arbitrary_unique_name()[:50],
            phone_number=data_gen.random_phonenumber(),
            domain=domain,
            direction=direction,
            date_sent=datetime.date(message_month_date.year, message_month_date.month,
                                    random.randint(1, last_day_message)),
        )
        sms_billable.save()
示例#9
0
 def apply_direction_and_domain_fee(self):
     for direction, domain_fee in self.most_specific_fees.items():
         for domain, amount in domain_fee.items():
             SmsUsageFee.create_new(direction, amount, domain=domain)
示例#10
0
 def apply_direction_fee(self):
     for direction, amount in self.least_specific_fees.items():
         SmsUsageFee.create_new(direction, amount)
示例#11
0
 def handle(self, *args, **options):
     SmsUsageFee.create_new(INCOMING, 0.01)
     SmsUsageFee.create_new(OUTGOING, 0.01)
     logger.info("Updated usage fees.")
示例#12
0
def bootstrap_usage_fees(apps):
    SmsUsageFee.create_new(INCOMING, 0.01)
    SmsUsageFee.create_new(OUTGOING, 0.01)
    log_smsbillables_info("Updated usage fees.")
示例#13
0
 def apply_direction_and_domain_fee(self):
     for direction, domain_fee in self.most_specific_fees.items():
         for domain, amount in domain_fee.items():
             SmsUsageFee.create_new(direction, amount, domain=domain)
示例#14
0
 def apply_direction_fee(self):
     for direction, amount in self.least_specific_fees.items():
         SmsUsageFee.create_new(direction, amount)
def bootstrap_usage_fees(apps):
    SmsUsageFee.create_new(INCOMING, 0.01)
    SmsUsageFee.create_new(OUTGOING, 0.01)
    log_smsbillables_info("Updated usage fees.")