2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-02 11:40:58 +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:
Oliver
2023-05-22 22:59:10 +10:00
committed by GitHub
parent f76059b2b4
commit 96b7845d84
2 changed files with 15 additions and 0 deletions

View File

@ -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)