diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 0632f78245..ef4d6f558a 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -764,6 +764,11 @@ CURRENCIES = get_setting( typecast=list, ) +# Ensure that at least one currency value is available +if len(CURRENCIES) == 0: # pragma: no cover + logger.warning("No currencies selected: Defaulting to USD") + CURRENCIES = ['USD'] + # Maximum number of decimal places for currency rendering CURRENCY_DECIMAL_PLACES = 6 diff --git a/InvenTree/common/migrations/0010_migrate_currency_setting.py b/InvenTree/common/migrations/0010_migrate_currency_setting.py index 0604e93008..09b0100db4 100644 --- a/InvenTree/common/migrations/0010_migrate_currency_setting.py +++ b/InvenTree/common/migrations/0010_migrate_currency_setting.py @@ -8,6 +8,16 @@ def set_default_currency(apps, schema_editor): """ migrate the currency setting from config.yml to db """ # get value from settings-file base_currency = get_setting('INVENTREE_BASE_CURRENCY', 'base_currency', 'USD') + + from common.settings import currency_codes + + # check if value is valid + if base_currency not in currency_codes(): + if len (currency_codes()) > 0: + base_currency = currency_codes()[0] + else: + base_currency = 'USD' + # write to database InvenTreeSetting.set_setting('INVENTREE_DEFAULT_CURRENCY', base_currency, None, create=True)