"""Currency helpers.""" from abacus_common_data.currency import Currency from ledger.constants.error import ERROR_UNKNOWN_CURRENCY def currency_exists(currency_code): """Check if a currency code exists.""" try: Currency(str(currency_code).upper()) return True except KeyError: return False def validate_currency(currency_code): """Validate whether given currency code is valid.""" if not currency_exists(currency_code): raise Exception(ERROR_UNKNOWN_CURRENCY.format(code=currency_code))