def parse_float_str(self, num_str): context = decimal.Context() value = decimal.Decimal(num_str).quantize( billing_quantization_exponent(), context=context) if (context.flags[decimal.Inexact] and value == decimal.Decimal('0.0')): raise self.DecodeError("Decimal quantization resulted in 0") return value
def parse_float_str(self, num_str): context = decimal.Context() value = decimal.Decimal(num_str).quantize( billing_quantization_exponent(), context=context) if (context.flags[decimal.Inexact] and value == decimal.Decimal('0.0')): raise self.DecodeError("Decimal quantization resulted in 0") return value
def default(self, obj): if isinstance(obj, decimal.Decimal): context = decimal.Context() value = obj.quantize(billing_quantization_exponent(), context=context) if (context.flags[decimal.Inexact] and value == decimal.Decimal('0.0')): raise self.EncodeError("Decimal quantization resulted in 0") return float(value) elif isinstance(obj, datetime.datetime): return obj.isoformat() else: return json.JSONEncoder.default(self, obj)
def default(self, obj): if isinstance(obj, decimal.Decimal): context = decimal.Context() value = obj.quantize(billing_quantization_exponent(), context=context) if (context.flags[decimal.Inexact] and value == decimal.Decimal('0.0')): raise self.EncodeError("Decimal quantization resulted in 0") return float(value) elif isinstance(obj, datetime.datetime): return obj.isoformat() else: return json.JSONEncoder.default(self, obj)
from decimal import Decimal from django.conf import settings from django.contrib.auth import get_user_model from go.config import billing_quantization_exponent # 10 credits = 1 US cent CREDIT_CONVERSION_FACTOR = getattr( settings, 'BILLING_CREDIT_CONVERSION_FACTOR', Decimal('10.00')) # This is currently pulled in from `go.config` to avoid pulling a pile of # Django stuff into `go.vumitools.billing_worker` through `go.billing.utils`. QUANTIZATION_EXPONENT = billing_quantization_exponent() if hasattr(settings, 'BILLING_QUANTIZATION_EXPONENT'): raise ValueError( "BILLING_QUANTIZATION_EXPONENT cannot be configured in settings.py.") API_MIN_CONNECTIONS = getattr(settings, 'BILLING_API_MIN_CONNECTIONS', 10) ENDPOINT_DESCRIPTION_STRING = getattr( settings, 'BILLING_ENDPOINT_DESCRIPTION_STRING', "tcp:9090:interface=127.0.0.1") MONTHLY_STATEMENT_TITLE = getattr( settings, 'BILLING_MONTHLY_STATEMENT_TITLE', "Monthly Statement") STATEMENTS_PER_PAGE = getattr( settings, 'BILLING_STATEMENTS_PER_PAGE', 12) STATEMENTS_DEFAULT_ORDER_BY = getattr(
from decimal import Decimal from django.conf import settings from django.contrib.auth import get_user_model from go.config import billing_quantization_exponent # 10 credits = 1 US cent CREDIT_CONVERSION_FACTOR = getattr(settings, 'BILLING_CREDIT_CONVERSION_FACTOR', Decimal('10.00')) # This is currently pulled in from `go.config` to avoid pulling a pile of # Django stuff into `go.vumitools.billing_worker` through `go.billing.utils`. QUANTIZATION_EXPONENT = billing_quantization_exponent() if hasattr(settings, 'BILLING_QUANTIZATION_EXPONENT'): raise ValueError( "BILLING_QUANTIZATION_EXPONENT cannot be configured in settings.py.") API_MIN_CONNECTIONS = getattr(settings, 'BILLING_API_MIN_CONNECTIONS', 10) ENDPOINT_DESCRIPTION_STRING = getattr(settings, 'BILLING_ENDPOINT_DESCRIPTION_STRING', "tcp:9090:interface=127.0.0.1") MONTHLY_STATEMENT_TITLE = getattr(settings, 'BILLING_MONTHLY_STATEMENT_TITLE', "Monthly Statement") STATEMENTS_PER_PAGE = getattr(settings, 'BILLING_STATEMENTS_PER_PAGE', 12) STATEMENTS_DEFAULT_ORDER_BY = getattr(settings,