本文整理汇总了Python中corehq.apps.smsbillables.models.SmsGatewayFee类的典型用法代码示例。如果您正苦于以下问题:Python SmsGatewayFee类的具体用法?Python SmsGatewayFee怎么用?Python SmsGatewayFee使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SmsGatewayFee类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bootstrap_smsgh_gateway
def bootstrap_smsgh_gateway(apps=None):
default_currency, _ = (apps.get_model("accounting", "Currency") if apps else Currency).objects.get_or_create(
code=settings.DEFAULT_CURRENCY
)
sms_gateway_fee_class = apps.get_model("smsbillables", "SmsGatewayFee") if apps else SmsGatewayFee
sms_gateway_fee_criteria_class = (
apps.get_model("smsbillables", "SmsGatewayFeeCriteria") if apps else SmsGatewayFeeCriteria
)
SmsGatewayFee.create_new(
SMSGHBackend.get_api_id(),
INCOMING,
Decimal("0.0"),
currency=default_currency,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
SmsGatewayFee.create_new(
SMSGHBackend.get_api_id(),
OUTGOING,
Decimal("0.0"),
currency=default_currency,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
logger.info("Updated SMSGH gateway fees.")
示例2: handle
def handle(self, *args, **options):
workbook = xlrd.open_workbook('corehq/apps/smsbillables/management/'
'commands/pricing_data/Syniverse_coverage_list_DIAMONDplus.xls')
table = workbook.sheet_by_index(0)
data = {}
try:
row = 7
while True:
if table.cell_value(row, 6) == 'yes':
country_code = int(table.cell_value(row, 0))
if not(country_code in data):
data[country_code] = []
subscribers = table.cell_value(row,10).replace('.', '')
try:
data[country_code].append(
(table.cell_value(row, 9), int(subscribers)))
except ValueError:
print 'Incomplete data for country code %d' % country_code
row += 1
except IndexError:
pass
for country_code in data:
total_subscribers = 0
weighted_price = 0
for price, subscribers in data[country_code]:
total_subscribers += subscribers
weighted_price += price * subscribers
weighted_price = weighted_price / total_subscribers
SmsGatewayFee.create_new(MachBackend.get_api_id(), OUTGOING, weighted_price,
country_code=country_code, currency=Currency.objects.get(code="EUR"))
print "Updated MACH/Syniverse gateway fees."
示例3: bootstrap_yo_gateway
def bootstrap_yo_gateway(orm):
ugx, _ = (orm['accounting.Currency'] if orm else Currency).objects.get_or_create(code='UGX')
sms_gateway_fee_class = orm['smsbillables.SmsGatewayFee'] if orm else SmsGatewayFee
sms_gateway_fee_criteria_class = orm['smsbillables.SmsGatewayFeeCriteria'] if orm else SmsGatewayFeeCriteria
SmsGatewayFee.create_new(
'YO',
INCOMING,
Decimal('110.0'),
currency=ugx,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
SmsGatewayFee.create_new(
'HTTP',
OUTGOING,
Decimal('55.0'),
backend_instance='95a4f0929cddb966e292e70a634da716',
currency=ugx,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
logger.info("Updated Yo gateway fees.")
示例4: add_moz_zero_charge
def add_moz_zero_charge(apps):
mzn, _ = (apps.get_model("accounting", "Currency") if apps else Currency).objects.get_or_create(code="MZN")
sms_gateway_fee_class = apps.get_model("smsbillables", "SmsGatewayFee") if apps else SmsGatewayFee
sms_gateway_fee_criteria_class = (
apps.get_model("smsbillables", "SmsGatewayFeeCriteria") if apps else SmsGatewayFeeCriteria
)
SmsGatewayFee.create_new(
SQLSislogBackend.get_api_id(),
INCOMING,
Decimal("0"),
country_code=None,
prefix="",
currency=mzn,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
SmsGatewayFee.create_new(
SQLSislogBackend.get_api_id(),
OUTGOING,
Decimal("0"),
country_code=None,
prefix="",
currency=mzn,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
logger.info("Updated Moz gateway default fees.")
示例5: add_moz_zero_charge
def add_moz_zero_charge(apps):
mzn, _ = (apps.get_model('accounting', 'Currency') if apps else Currency).objects.get_or_create(code='MZN')
sms_gateway_fee_class = apps.get_model('smsbillables', 'SmsGatewayFee') if apps else SmsGatewayFee
sms_gateway_fee_criteria_class = apps.get_model('smsbillables', 'SmsGatewayFeeCriteria') if apps else SmsGatewayFeeCriteria
SmsGatewayFee.create_new(
SQLSislogBackend.get_api_id(),
INCOMING,
Decimal('0'),
country_code=None,
prefix='',
currency=mzn,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
SmsGatewayFee.create_new(
SQLSislogBackend.get_api_id(),
OUTGOING,
Decimal('0'),
country_code=None,
prefix='',
currency=mzn,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
log_smsbillables_info("Updated Moz gateway default fees.")
示例6: update_sislog_vodacom_mozambique_fees
def update_sislog_vodacom_mozambique_fees(apps, schema_editor):
mzn, _ = apps.get_model('accounting', 'Currency').objects.get_or_create(code='MZN')
sms_gateway_fee_class = apps.get_model('smsbillables', 'SmsGatewayFee')
sms_gateway_fee_criteria_class = apps.get_model('smsbillables', 'SmsGatewayFeeCriteria')
country_code = 258
for prefix in ['84', '85']:
SmsGatewayFee.create_new(
SQLSislogBackend.get_api_id(),
INCOMING,
Decimal('2.0'),
country_code=country_code,
prefix=prefix,
currency=mzn,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
SmsGatewayFee.create_new(
SQLSislogBackend.get_api_id(),
OUTGOING,
Decimal('0.35'),
country_code=country_code,
prefix=prefix,
currency=mzn,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
示例7: bootstrap_mach_gateway
def bootstrap_mach_gateway(apps):
currency_class = apps.get_model("accounting", "Currency") if apps else Currency
sms_gateway_fee_class = apps.get_model("smsbillables", "SmsGatewayFee") if apps else SmsGatewayFee
sms_gateway_fee_criteria_class = (
apps.get_model("smsbillables", "SmsGatewayFeeCriteria") if apps else SmsGatewayFeeCriteria
)
workbook = xlrd.open_workbook(
"corehq/apps/smsbillables/management/" "commands/pricing_data/Syniverse_coverage_list_DIAMONDplus.xls"
)
table = workbook.sheet_by_index(0)
data = {}
try:
row = 7
while True:
if table.cell_value(row, 6) == "yes":
country_code = int(table.cell_value(row, 0))
if not (country_code in data):
data[country_code] = []
subscribers = table.cell_value(row, 10).replace(".", "")
try:
data[country_code].append((table.cell_value(row, 9), int(subscribers)))
except ValueError:
logger.info("Incomplete data for country code %d" % country_code)
row += 1
except IndexError:
pass
for country_code in data:
total_subscribers = 0
weighted_price = 0
for price, subscribers in data[country_code]:
total_subscribers += subscribers
weighted_price += price * subscribers
weighted_price = weighted_price / total_subscribers
SmsGatewayFee.create_new(
MachBackend.get_api_id(),
OUTGOING,
weighted_price,
country_code=country_code,
currency=currency_class.objects.get(code="EUR"),
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
# Fee for invalid phonenumber
SmsGatewayFee.create_new(
MachBackend.get_api_id(),
OUTGOING,
0.0225,
country_code=None,
currency=currency_class.objects.get(code="EUR"),
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
logger.info("Updated MACH/Syniverse gateway fees.")
示例8: bootstrap_unicel_gateway
def bootstrap_unicel_gateway(apps):
currency = (apps.get_model('accounting.Currency') if apps else Currency).objects.get(code="INR")
sms_gateway_fee_class = apps.get_model('smsbillables.SmsGatewayFee') if apps else SmsGatewayFee
sms_gateway_fee_criteria_class = apps.get_model('smsbillables.SmsGatewayFeeCriteria') if apps else SmsGatewayFeeCriteria
SmsGatewayFee.create_new(SQLUnicelBackend.get_api_id(), INCOMING, 0.50,
currency=currency,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class)
SmsGatewayFee.create_new(SQLUnicelBackend.get_api_id(), OUTGOING, 0.50,
currency=currency,
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class)
logger.info("Updated Unicel gateway fees.")
示例9: create_prefix_gateway_fees
def create_prefix_gateway_fees(self):
for direction, backend in self.prefix_fees.items():
for backend_api_id, country in backend.items():
for country_code, prfx in country.items():
for prefix, backend_instance_and_amount in prfx.items():
for backend_instance, amount in backend_instance_and_amount.items():
SmsGatewayFee.create_new(
backend_api_id,
direction,
amount,
country_code=country_code,
prefix=prefix,
backend_instance=backend_instance,
)
示例10: handle
def handle(self, *args, **options):
SmsGatewayFee.create_new(TropoBackend.get_api_id(), INCOMING, 0.01)
rates_csv = open('corehq/apps/smsbillables/management/'
'pricing_data/tropo_international_rates_2013-12-19.csv', 'r')
for line in rates_csv.readlines():
data = line.split(',')
if data[1] == 'Fixed Line' and data[4] != '\n':
SmsGatewayFee.create_new(TropoBackend.get_api_id(),
OUTGOING,
float(data[4].rstrip()),
country_code=int(data[2]))
rates_csv.close()
print "Updated Tropo gateway fees."
示例11: arbitrary_sms_billables_for_domain
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
示例12: get_rate_response
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),
}
示例13: bootstrap_twilio_gateway_incoming
def bootstrap_twilio_gateway_incoming(apps):
currency_class = apps.get_model('accounting', 'Currency') if apps else Currency
sms_gateway_fee_class = apps.get_model('smsbillables', 'SmsGatewayFee') if apps else SmsGatewayFee
sms_gateway_fee_criteria_class = apps.get_model('smsbillables', 'SmsGatewayFeeCriteria') if apps else SmsGatewayFeeCriteria
# https://www.twilio.com/sms/pricing/us
SmsGatewayFee.create_new(
SQLTwilioBackend.get_api_id(),
INCOMING,
0.0075,
country_code=None,
currency=currency_class.objects.get(code="USD"),
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
log_smsbillables_info("Updated INCOMING Twilio gateway fees.")
示例14: bootstrap_twilio_gateway_incoming
def bootstrap_twilio_gateway_incoming(orm):
currency_class = orm['accounting.Currency'] if orm else Currency
sms_gateway_fee_class = orm['smsbillables.SmsGatewayFee'] if orm else SmsGatewayFee
sms_gateway_fee_criteria_class = orm['smsbillables.SmsGatewayFeeCriteria'] if orm else SmsGatewayFeeCriteria
# https://www.twilio.com/sms/pricing/us
SmsGatewayFee.create_new(
TwilioBackend.get_api_id(),
INCOMING,
0.0075,
country_code=None,
currency=currency_class.objects.get(code="USD"),
fee_class=sms_gateway_fee_class,
criteria_class=sms_gateway_fee_criteria_class,
)
logger.info("Updated INCOMING Twilio gateway fees.")
示例15: _directed_fee
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)