def generate_cdr(self, applied_parts, time_stamp): cdrs = [] self._cdr_info['time_stamp'] = time_stamp self._cdr_info['type'] = 'C' # Check the type of the applied parts if 'single_payment' in applied_parts: # A cdr is generated for every price part for part in applied_parts['single_payment']: description = 'One time payment: ' + unicode( part['value']) + ' ' + self._cdr_info['cost_currency'] cdrs.append( self._generate_cdr_part(part, 'One time payment event', description)) if 'subscription' in applied_parts: # A cdr is generated by price part for part in applied_parts['subscription']: description = 'Recurring payment: ' + unicode(part['value']) + ' ' + self._cdr_info['cost_currency'] \ + ' ' + part['unit'] cdrs.append( self._generate_cdr_part(part, 'Recurring payment event', description)) if 'accounting' in applied_parts: # A cdr is generated by price part for part in applied_parts['accounting']: use_part = { 'value': part['price'], 'duty_free': part['duty_free'], } # Calculate the total consumption use = 0 for sdr in part['accounting']: use += int(sdr['value']) description = 'Fee per ' + part['model'][ 'unit'] + ', Consumption: ' + unicode(use) cdrs.append( self._generate_cdr_part(use_part, 'Pay per use event', description)) # Send the created CDRs to the Revenue Sharing System r = RSSAdaptorThread(cdrs) r.start()
def refund_cdrs(self, price, duty_free, time_stamp): self._cdr_info['time_stamp'] = time_stamp self._cdr_info['type'] = 'R' # Create a payment part representing the whole payment aggregated_part = { 'value': price, 'duty_free': duty_free, } description = 'Refund event: ' + unicode(price) + ' ' + self._cdr_info['cost_currency'] cdrs = [self._generate_cdr_part(aggregated_part, 'Refund event', description)] # Send the created CDRs to the Revenue Sharing System r = RSSAdaptorThread(cdrs) r.start()
def refund_cdrs(self, price, duty_free, time_stamp): self._cdr_info['time_stamp'] = time_stamp self._cdr_info['type'] = 'R' # Create a payment part representing the whole payment aggregated_part = { 'value': price, 'duty_free': duty_free, } description = 'Refund event: ' + str(price) + ' ' + self._cdr_info['cost_currency'] cdrs = [self._generate_cdr_part(aggregated_part, 'Refund event', description)] # Send the created CDRs to the Revenue Sharing System r = RSSAdaptorThread(cdrs) r.start()
def generate_cdr(self, applied_parts, time_stamp): cdrs = [] self._cdr_info['time_stamp'] = time_stamp self._cdr_info['type'] = 'C' # Check the type of the applied parts if 'single_payment' in applied_parts: # A cdr is generated for every price part for part in applied_parts['single_payment']: description = 'One time payment: ' + unicode(part['value']) + ' ' + self._cdr_info['cost_currency'] cdrs.append(self._generate_cdr_part(part, 'One time payment event', description)) if 'subscription' in applied_parts: # A cdr is generated by price part for part in applied_parts['subscription']: description = 'Recurring payment: ' + unicode(part['value']) + ' ' + self._cdr_info['cost_currency'] \ + ' ' + part['unit'] cdrs.append(self._generate_cdr_part(part, 'Recurring payment event', description)) if 'accounting' in applied_parts: # A cdr is generated by price part for part in applied_parts['accounting']: use_part = { 'value': part['price'], 'duty_free': part['duty_free'], } # Calculate the total consumption use = 0 for sdr in part['accounting']: use += int(sdr['value']) description = 'Fee per ' + part['model']['unit'] + ', Consumption: ' + unicode(use) cdrs.append(self._generate_cdr_part(use_part, 'Pay per use event', description)) # Send the created CDRs to the Revenue Sharing System r = RSSAdaptorThread(cdrs) r.start()
def _generate_cdr(self, applied_parts, time_stamp, price=None): cdrs = [] # Take the first RSS registered rss_collection = RSS.objects.all() if len(rss_collection) > 0: rss = RSS.objects.all()[0] # Get the service name using direct access to the stored # JSON USDL description offering_description = self._purchase.offering.offering_description # Get the used tag for RDF properties service_tag = '' dc_tag = '' for k, v in offering_description['@context'].iteritems(): if v == 'http://www.linked-usdl.org/ns/usdl-core#': service_tag = k if v == 'http://purl.org/dc/terms/': dc_tag = k # Get the service name service_name = '' for node in offering_description['@graph']: if node['@type'] == service_tag + ':Service': service_name = node[dc_tag + ':title']['@value'] # Get the provider (Organization) provider = self._purchase.offering.owner_organization.name # Set offering ID offering = self._purchase.offering.name + ' ' + self._purchase.offering.version # Get the customer if self._purchase.organization_owned: customer = self._purchase.owner_organization.name else: customer = self._purchase.customer.username # Get the country code country_code = self._get_country_code(self._purchase.tax_address['country']) country_code = get_country_code(country_code) cdr_info = { 'rss': rss, 'provider': provider, 'service_name': service_name, 'offering': offering, 'country_code': country_code, 'time_stamp': time_stamp, 'customer': customer } # If any deduction has been applied the whole payment is # included in a single CDR instead of including parts in # order to avoid a mismatch between the revenues being shared # and the real payment if price: # Create a payment part representing the whole payment aggregated_part = { 'value': price, 'currency': self._price_model['general_currency'] } cdr_info['description'] = 'Complete Charging event: ' + str(price) + ' ' + self._price_model['general_currency'] cdrs.append(self._generate_cdr(aggregated_part, 'Charging event', cdr_info)) else: # Check the type of the applied parts if 'single_payment' in applied_parts: # A cdr is generated for every price part for part in applied_parts['single_payment']: cdr_info['description'] = 'Single payment: ' + part['value'] + ' ' + part['currency'] cdrs.append(self._generate_cdr_part(part, 'Single payment event', cdr_info)) if 'subscription' in applied_parts: # A cdr is generated by price part for part in applied_parts['subscription']: cdr_info['description'] = 'Subscription: ' + part['value'] + ' ' + part['currency'] + ' ' + part['unit'] cdrs.append(self._generate_cdr_part(part, 'Subscription event', cdr_info)) if 'charges' in applied_parts: # A cdr is generated by price part for part in applied_parts['charges']: use_part = { 'value': part['price'], } if 'price_function' in part['model']: cdr_info['description'] = part['model']['text_function'] use_part['currency'] = self._price_model['general_currency'] else: use_part['currency'] = part['model']['currency'] # Calculate the total consumption use = 0 for sdr in part['accounting']: use += int(sdr['value']) cdr_info['description'] = 'Fee per ' + part['model']['unit'] + ', Consumption: ' + str(use) cdrs.append(self._generate_cdr_part(use_part, 'Pay per use event', cdr_info)) # Send the created CDRs to the Revenue Sharing System r = RSSAdaptorThread(rss, cdrs) r.start()
def _generate_cdr(self, applied_parts, time_stamp, price=None): cdrs = [] # Take the first RSS registered rss_collection = RSS.objects.all() if len(rss_collection) > 0: rss = RSS.objects.all()[0] # Get the provider (Organization) if rss.api_version == 1: provider = settings.STORE_NAME.lower() + '-provider' else: provider = self._purchase.offering.owner_organization.actor_id # Set offering ID offering = self._purchase.offering.name + ' ' + self._purchase.offering.version # Get the customer customer = self._purchase.owner_organization.name # Get the country code try: country_code = self._get_country_code( self._purchase.tax_address['country']) country_code = get_country_code(country_code) except: country_code = '1' # Get the product class if rss.api_version == 1: product_class = self._purchase.contract.revenue_class else: off_model = self._purchase.offering product_class = off_model.owner_organization.name + '/' + off_model.name + '/' + off_model.version cdr_info = { 'rss': rss, 'provider': provider, 'service_name': offering, 'offering': offering, 'country_code': country_code, 'time_stamp': time_stamp, 'customer': customer, 'product_class': product_class } # If any deduction has been applied the whole payment is # included in a single CDR instead of including parts in # order to avoid a mismatch between the revenues being shared # and the real payment if price: # Create a payment part representing the whole payment aggregated_part = { 'value': price, 'currency': self._price_model['general_currency'] } cdr_info['description'] = 'Complete Charging event: ' + str( price) + ' ' + self._price_model['general_currency'] cdrs.append( self._generate_cdr_part(aggregated_part, 'Charging event', cdr_info)) else: # Check the type of the applied parts if 'single_payment' in applied_parts: # A cdr is generated for every price part for part in applied_parts['single_payment']: cdr_info['description'] = 'Single payment: ' + part[ 'value'] + ' ' + self._price_model[ 'general_currency'] cdrs.append( self._generate_cdr_part(part, 'Single payment event', cdr_info)) if 'subscription' in applied_parts: # A cdr is generated by price part for part in applied_parts['subscription']: cdr_info['description'] = 'Subscription: ' + part[ 'value'] + ' ' + self._price_model[ 'general_currency'] + ' ' + part['unit'] cdrs.append( self._generate_cdr_part(part, 'Subscription event', cdr_info)) if 'charges' in applied_parts: # A cdr is generated by price part for part in applied_parts['charges']: use_part = { 'value': part['price'], } if 'price_function' in part['model']: cdr_info['description'] = part['model'][ 'text_function'] use_part['currency'] = self._price_model[ 'general_currency'] else: use_part['currency'] = self._price_model[ 'general_currency'] # Calculate the total consumption use = 0 for sdr in part['accounting']: use += int(sdr['value']) cdr_info['description'] = 'Fee per ' + part[ 'model']['unit'] + ', Consumption: ' + str(use) cdrs.append( self._generate_cdr_part(use_part, 'Pay per use event', cdr_info)) # Send the created CDRs to the Revenue Sharing System r = RSSAdaptorThread(rss, cdrs) r.start()
def _generate_cdr(self, applied_parts, time_stamp, price=None): cdrs = [] # Take the first RSS registered rss_collection = RSS.objects.all() if len(rss_collection) > 0: rss = RSS.objects.all()[0] # Get the provider (Organization) if rss.api_version == 1: provider = settings.STORE_NAME.lower() + '-provider' else: provider = self._purchase.offering.owner_organization.actor_id # Set offering ID offering = self._purchase.offering.name + ' ' + self._purchase.offering.version # Get the customer customer = self._purchase.owner_organization.name # Get the country code try: country_code = self._get_country_code(self._purchase.tax_address['country']) country_code = get_country_code(country_code) except: country_code = '1' # Get the product class if rss.api_version == 1: product_class = self._purchase.contract.revenue_class else: off_model = self._purchase.offering product_class = off_model.owner_organization.name + '/' + off_model.name + '/' + off_model.version cdr_info = { 'rss': rss, 'provider': provider, 'service_name': offering, 'offering': offering, 'country_code': country_code, 'time_stamp': time_stamp, 'customer': customer, 'product_class': product_class } # If any deduction has been applied the whole payment is # included in a single CDR instead of including parts in # order to avoid a mismatch between the revenues being shared # and the real payment if price: # Create a payment part representing the whole payment aggregated_part = { 'value': price, 'currency': self._price_model['general_currency'] } cdr_info['description'] = 'Complete Charging event: ' + str(price) + ' ' + self._price_model['general_currency'] cdrs.append(self._generate_cdr_part(aggregated_part, 'Charging event', cdr_info)) else: # Check the type of the applied parts if 'single_payment' in applied_parts: # A cdr is generated for every price part for part in applied_parts['single_payment']: cdr_info['description'] = 'Single payment: ' + part['value'] + ' ' + self._price_model['general_currency'] cdrs.append(self._generate_cdr_part(part, 'Single payment event', cdr_info)) if 'subscription' in applied_parts: # A cdr is generated by price part for part in applied_parts['subscription']: cdr_info['description'] = 'Subscription: ' + part['value'] + ' ' + self._price_model['general_currency'] + ' ' + part['unit'] cdrs.append(self._generate_cdr_part(part, 'Subscription event', cdr_info)) if 'charges' in applied_parts: # A cdr is generated by price part for part in applied_parts['charges']: use_part = { 'value': part['price'], } if 'price_function' in part['model']: cdr_info['description'] = part['model']['text_function'] use_part['currency'] = self._price_model['general_currency'] else: use_part['currency'] = self._price_model['general_currency'] # Calculate the total consumption use = 0 for sdr in part['accounting']: use += int(sdr['value']) cdr_info['description'] = 'Fee per ' + part['model']['unit'] + ', Consumption: ' + str(use) cdrs.append(self._generate_cdr_part(use_part, 'Pay per use event', cdr_info)) # Send the created CDRs to the Revenue Sharing System r = RSSAdaptorThread(rss, cdrs) r.start()