mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fix for currency migration (#4873)
- Handle case where no currencies are provided
- Handle case where base currency is not in provided options
(cherry picked from commit b1bf086ae9
)
This commit is contained in:
parent
f76059b2b4
commit
96b7845d84
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user