def get_currency_for_country(country): currencies = get_territory_currencies(country.code) if len(currencies): main_currency = currencies[0] if main_currency in settings.AVAILABLE_CURRENCIES: return main_currency return settings.DEFAULT_CURRENCY
def test_get_territory_currencies(): assert numbers.get_territory_currencies('AT', date(1995, 1, 1)) == ['ATS'] assert numbers.get_territory_currencies('AT', date(2011, 1, 1)) == ['EUR'] assert numbers.get_territory_currencies('US', date(2013, 1, 1)) == ['USD'] assert sorted( numbers.get_territory_currencies( 'US', date(2013, 1, 1), non_tender=True)) == ['USD', 'USN', 'USS'] assert numbers.get_territory_currencies('US', date(2013, 1, 1), include_details=True) == [{ 'currency': 'USD', 'from': date(1792, 1, 1), 'to': None, 'tender': True }] assert numbers.get_territory_currencies('LS', date(2013, 1, 1)) == ['ZAR', 'LSL'] assert numbers.get_territory_currencies('QO', date(2013, 1, 1)) == []
def get_active_currencies(): active_currencies = [] territories = get_global('territory_currencies').keys() for territory in territories: currencies = get_territory_currencies(territory, datetime.date.today()) if currencies: for currency in currencies: if currency not in active_currencies: active_currencies.append(currencies[0]) return active_currencies
def format_currency_field(__, prec, number, locale): """Formats a currency field.""" locale = Locale.parse(locale) currency = get_territory_currencies(locale.territory)[0] if prec is None: pattern, currency_digits = None, True else: prec = int(prec) pattern = locale.currency_formats['standard'] pattern = modify_number_pattern(pattern, frac_prec=(prec, prec)) currency_digits = False return format_currency(number, currency, pattern, locale=locale, currency_digits=currency_digits)
def get_territory_currencies( self, start_date=None, end_date=None, tender=True, non_tender=False, include_details=False ): """Returns the list of currencies for the given territory that are valid for the given date range In: - ``start_date`` -- the start date. If not given today is assumed - ``end_date`` -- the end date. If not given the start date is assumed - ``tender`` -- controls whether tender currencies should be included - ``non_tender`` -- controls whether non-tender currencies should be included - ``include_detail`` -- the return value will be a dictionnary Return: - the currencies """ return numbers.get_territory_currencies(self.territory, start_date, end_date, tender, non_tender, include_details)
def create_tenant(domain='', **extra_fields): extra_fields.setdefault('name', '') extra_fields.setdefault('country', '') extra_fields.setdefault('currency', '') if domain and not freemail.is_free(domain): # We can guess some field values based on the domain. tld = tldextract.extract(domain) geo_ip = GeoIP2() if not extra_fields['name']: # Use the domain of the email address as tenant name. extra_fields['name'] = tld.domain.title() if not extra_fields['country']: try: country_code = geo_ip.country( tld.registered_domain).get('country_code') except (gaierror, AddressNotFoundError): pass else: if country_code in [c[0] for c in COUNTRIES]: extra_fields['country'] = country_code if extra_fields['country'] and not extra_fields['currency']: currency = get_territory_currencies( extra_fields['country'])[-1] if currency in [c[0] for c in CURRENCIES]: extra_fields['currency'] = currency if settings.BILLING_ENABLED: # Chargebee needs extra info on who to bill, so for now only create the plans without activating the trial. plan, created = Plan.objects.get_or_create( name=settings.CHARGEBEE_PRO_TRIAL_PLAN_NAME) billing = Billing.objects.create(plan=plan) else: billing = Billing.objects.create() tenant = Tenant.objects.create(billing=billing, **extra_fields) create_defaults_for_tenant(tenant) return tenant
def test_get_territory_currencies(): assert numbers.get_territory_currencies('AT', date(1995, 1, 1)) == ['ATS'] assert numbers.get_territory_currencies('AT', date(2011, 1, 1)) == ['EUR'] assert numbers.get_territory_currencies('US', date(2013, 1, 1)) == ['USD'] assert sorted(numbers.get_territory_currencies('US', date(2013, 1, 1), non_tender=True)) == ['USD', 'USN', 'USS'] assert numbers.get_territory_currencies('US', date(2013, 1, 1), include_details=True) == [{ 'currency': 'USD', 'from': date(1792, 1, 1), 'to': None, 'tender': True }] assert numbers.get_territory_currencies('LS', date(2013, 1, 1)) == ['ZAR', 'LSL'] assert numbers.get_territory_currencies('QO', date(2013, 1, 1)) == []
def get_currency_for_country(country): currencies = get_territory_currencies(country.code) if len(currencies): return currencies[0] return settings.DEFAULT_CURRENCY
def get_currency_for_country(country): currencies = get_territory_currencies(country.code) if currencies: return currencies[0] return os.environ.get("DEFAULT_CURRENCY", "USD")
def get_currency_for_country(country): currencies = get_territory_currencies(country.code) if currencies: return currencies[0] return settings.DEFAULT_CURRENCY
def load_for_locale(locale, parent): ''' Load Localized Currency Data for a Single Locale Localized data stored for each locale includes: LC_NUMERIC Information ---------------------- - Decimal Point Symbol - Digit Grouping Symbol - Plus Sign - Minus Sign - Percent Sign - Permille Sign - Exponential Sign - Superscripting Exponent - String representing infinity - String representing a non-numeric value Currency Formatting Information ------------------------------- - Basic Numeric Format - Currency Numeric Format - Accounting Numeric Format Currency Localization Data -------------------------- - Localized Currency Symbols - Localized Currency Names - Local Default Currency ''' L = Locale.parse(locale) data = dict() # Load Locale Information data = { 'd' : L.number_symbols['decimal'], 'g' : L.number_symbols['group'], 'p' : L.number_symbols['plusSign'], 'm' : L.number_symbols['minusSign'], 'pc' : L.number_symbols['percentSign'], 'pm' : L.number_symbols['perMille'], 'e' : L.number_symbols['exponential'], 'x' : L.number_symbols['superscriptingExponent'], 'inf': L.number_symbols['infinity'], 'nan': L.number_symbols['nan'], 'np' : L.decimal_formats[None].pattern, 'cp' : L.currency_formats['standard'].pattern, 'ap' : L.currency_formats['accounting'].pattern, # Currency Symbols 'cs' : dict([ (k, v) for k, v in L.currency_symbols.items() if k in NVLPS_CURRENCY_LIST ]), # Currency Names 'cn' : dict([ (k, v) for k, v in L.currencies.items() if k in NVLPS_CURRENCY_LIST ]), } # Load Locale Currency territory = L.territory if (territory is None) and (L.language in NVLPS_LOCALE_ALIASES): territory = parse_locale(NVLPS_LOCALE_ALIASES[L.language])[1] if territory is not None: currencies = get_territory_currencies(territory) if currencies and len(currencies) > 0: data['c'] = currencies[0] # Remove Redundant Information contained in Parent if parent is not None: data = make_locale_overlay(data, parent) # Return Locale Data return data if len(data) > 0 else None