def bootstrap_icds_gateway(apps=None): usd_currency, _ = (apps.get_model('accounting', 'Currency') if apps else Currency).objects.get_or_create(code="USD") 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( SQLICDSBackend.get_api_id(), INCOMING, Decimal('0.0'), currency=usd_currency, fee_class=sms_gateway_fee_class, criteria_class=sms_gateway_fee_criteria_class, ) SmsGatewayFee.create_new( SQLICDSBackend.get_api_id(), OUTGOING, Decimal('0.0'), currency=usd_currency, fee_class=sms_gateway_fee_class, criteria_class=sms_gateway_fee_criteria_class, ) log_smsbillables_info("Updated ICDS gateway fees.")
def get_records(self, domain, start_timestamp, end_timestamp, indicator_filter=None, state_filter=None): indicator_filter = indicator_filter or [] state_filter = state_filter or [] if not isinstance(indicator_filter, list): raise TypeError("Expected list for indicator_filter") if not isinstance(state_filter, list): raise TypeError("Expected list for state_filter") for sms in SMS.objects.filter( domain=domain, date__gt=start_timestamp, date__lte=end_timestamp, backend_api=SQLICDSBackend.get_api_id(), direction='O', processed=True, ).order_by('date'): recipient_details = self.get_recipient_details(sms) location_details = self.get_location_details( recipient_details['location_id']) indicator_slug = self.get_indicator_slug(sms) if indicator_filter and indicator_slug not in indicator_filter: continue if state_filter and location_details['state'].get( 'site_code') not in state_filter: continue yield ( self.format_timestamp(sms.date), sms.phone_number, recipient_details['name'], location_details['state'].get('name'), location_details['district'].get('name'), location_details['block'].get('name'), location_details['supervisor'].get('name'), location_details['awc'].get('name'), sms.text, recipient_details['type'], sms.couch_recipient, indicator_slug, location_details['state'].get('location_id'), location_details['district'].get('location_id'), location_details['block'].get('location_id'), location_details['supervisor'].get('location_id'), location_details['awc'].get('location_id'), )
def handle(self, domain, **options): for sms in SMS.objects.filter( domain=domain, backend_api=SQLICDSBackend.get_api_id(), direction='O', processed=True, date__lt=datetime(2017, 6, 26), ): if sms.custom_metadata: continue slug, num_matches = self.get_indicator_slug(sms) if num_matches == 1: sms.custom_metadata = {'icds_indicator': slug} sms.save()
def bootstrap_icds_gateway(apps=None): usd_currency, _ = (apps.get_model('accounting', 'Currency') if apps else Currency).objects.get_or_create(code="USD") 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( SQLICDSBackend.get_api_id(), INCOMING, Decimal('0.0'), currency=usd_currency, fee_class=sms_gateway_fee_class, criteria_class=sms_gateway_fee_criteria_class, ) SmsGatewayFee.create_new( SQLICDSBackend.get_api_id(), OUTGOING, Decimal('0.0'), currency=usd_currency, fee_class=sms_gateway_fee_class, criteria_class=sms_gateway_fee_criteria_class, ) log_smsbillables_info("Updated ICDS gateway fees.")
def handle(self, domain, start_date, end_date, **options): start_timestamp, end_timestamp = self.get_start_and_end_timestamps(start_date, end_date) self.recipient_id_to_location_id = {} self.location_id_to_location = {} self.location_id_to_state_code = {} self.state_code_to_name = {'unknown': 'Unknown'} data = {} filename = 'icds-sms-usage--%s--%s.xlsx' % ( start_date.strftime('%Y-%m-%d'), end_date.strftime('%Y-%m-%d'), ) for sms in SMS.objects.filter( domain=domain, date__gt=start_timestamp, date__lte=end_timestamp, backend_api=SQLICDSBackend.get_api_id(), direction='O', processed=True, ): location = self.get_location(sms) state_code = self.get_state_code(location) if state_code not in data: data[state_code] = {} indicator_slug = self.get_indicator_slug(sms) if indicator_slug not in data[state_code]: data[state_code][indicator_slug] = 0 data[state_code][indicator_slug] += 1 with open(filename, 'wb') as f: headers = ('State Code', 'State Name', 'Indicator', 'SMS Count') excel_data = [] for state_code, state_data in data.items(): for indicator_slug, count in state_data.items(): excel_data.append((state_code, self.state_code_to_name[state_code], indicator_slug, count)) export_raw( (('icds-sms-usage', headers), ), (('icds-sms-usage', excel_data), ), f )