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/pricing_data/Syniverse_coverage_list_PREMIUM_Sept2019.xlsx') 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: log_smsbillables_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 if total_subscribers == 0: continue weighted_price = weighted_price / total_subscribers SmsGatewayFee.create_new( SQLMachBackend.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( SQLMachBackend.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, ) log_smsbillables_info("Updated MACH/Syniverse gateway fees.")
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: log_smsbillables_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( SQLMachBackend.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( SQLMachBackend.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, ) log_smsbillables_info("Updated MACH/Syniverse gateway fees.")
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 filename = 'corehq/apps/smsbillables/management/pricing_data/Syniverse_coverage_list_PREMIUM_Sept2019.xlsx' workbook = openpyxl.load_workbook(filename, read_only=True, data_only=True) table = workbook.worksheets[0] data = {} for row in islice(table.rows, 7, None): if row[6].value == 'yes': country_code = int(row[0].value) if not(country_code in data): data[country_code] = [] subscribers = row[10].value.replace('.', '') try: data[country_code].append((row[9].value, int(subscribers))) except ValueError: log_smsbillables_info('Incomplete data for country code %d' % country_code) 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 if total_subscribers == 0: continue weighted_price = weighted_price / total_subscribers SmsGatewayFee.create_new( SQLMachBackend.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( SQLMachBackend.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, ) log_smsbillables_info("Updated MACH/Syniverse gateway fees.")
def setUp(self): super(AllBackendTest, self).setUp() self.domain_obj = Domain(name='all-backend-test') self.domain_obj.save() self.create_account_and_subscription(self.domain_obj.name) self.domain_obj = Domain.get(self.domain_obj._id) self.test_phone_number = '99912345' self.contact1 = CommCareCase(domain=self.domain_obj.name) self.contact1.set_case_property('contact_phone_number', self.test_phone_number) self.contact1.set_case_property('contact_phone_number_is_verified', '1') self.contact1.save() self.contact1 = CommConnectCase.wrap(self.contact1.to_json()) # For use with megamobile only self.contact2 = CommCareCase(domain=self.domain_obj.name) self.contact2.set_case_property('contact_phone_number', '63%s' % self.test_phone_number) self.contact2.set_case_property('contact_phone_number_is_verified', '1') self.contact2.save() self.contact2 = CommConnectCase.wrap(self.contact2.to_json()) self.unicel_backend = SQLUnicelBackend( name='UNICEL', is_global=True, hq_api_id=SQLUnicelBackend.get_api_id() ) self.unicel_backend.save() self.mach_backend = SQLMachBackend( name='MACH', is_global=True, hq_api_id=SQLMachBackend.get_api_id() ) self.mach_backend.save() self.tropo_backend = SQLTropoBackend( name='TROPO', is_global=True, hq_api_id=SQLTropoBackend.get_api_id() ) self.tropo_backend.save() self.http_backend = SQLHttpBackend( name='HTTP', is_global=True, hq_api_id=SQLHttpBackend.get_api_id() ) self.http_backend.save() self.telerivet_backend = SQLTelerivetBackend( name='TELERIVET', is_global=True, hq_api_id=SQLTelerivetBackend.get_api_id() ) self.telerivet_backend.set_extra_fields( **dict( webhook_secret='telerivet-webhook-secret' ) ) self.telerivet_backend.save() self.test_backend = SQLTestSMSBackend( name='TEST', is_global=True, hq_api_id=SQLTestSMSBackend.get_api_id() ) self.test_backend.save() self.grapevine_backend = SQLGrapevineBackend( name='GRAPEVINE', is_global=True, hq_api_id=SQLGrapevineBackend.get_api_id() ) self.grapevine_backend.save() self.twilio_backend = SQLTwilioBackend( name='TWILIO', is_global=True, hq_api_id=SQLTwilioBackend.get_api_id() ) self.twilio_backend.save() self.megamobile_backend = SQLMegamobileBackend( name='MEGAMOBILE', is_global=True, hq_api_id=SQLMegamobileBackend.get_api_id() ) self.megamobile_backend.save() self.smsgh_backend = SQLSMSGHBackend( name='SMSGH', is_global=True, hq_api_id=SQLSMSGHBackend.get_api_id() ) self.smsgh_backend.save() self.apposit_backend = SQLAppositBackend( name='APPOSIT', is_global=True, hq_api_id=SQLAppositBackend.get_api_id() ) self.apposit_backend.save() self.sislog_backend = SQLSislogBackend( name='SISLOG', is_global=True, hq_api_id=SQLSislogBackend.get_api_id() ) self.sislog_backend.save() self.yo_backend = SQLYoBackend( name='YO', is_global=True, hq_api_id=SQLYoBackend.get_api_id() ) self.yo_backend.save()