"""Currency helpers.""" from abacus_common_data.currency import Currency from marshmallow import ValidationError from abacus_worksheet.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_exists(currency_code): """Return error if currency does not exist.""" if currency_exists(currency_code): return raise ValidationError(ERROR_UNKNOWN_CURRENCY.format(code=currency_code))