diff --git a/InvenTree/InvenTree/exchange.py b/InvenTree/InvenTree/exchange.py index f5c1ad4d48..149ef6b794 100644 --- a/InvenTree/InvenTree/exchange.py +++ b/InvenTree/InvenTree/exchange.py @@ -1,5 +1,5 @@ from django.conf import settings as inventree_settings -from common.settings import currency_code_default +from common.settings import currency_code_default, currency_codes from djmoney.contrib.exchange.backends.base import SimpleExchangeBackend @@ -25,6 +25,6 @@ class InvenTreeExchange(SimpleExchangeBackend): def update_rates(self, base_currency=currency_code_default()): - symbols = ','.join(inventree_settings.CURRENCIES) + symbols = ','.join(currency_codes()) super().update_rates(base=base_currency, symbols=symbols) diff --git a/InvenTree/InvenTree/tasks.py b/InvenTree/InvenTree/tasks.py index 6397ea72e7..b01b362760 100644 --- a/InvenTree/InvenTree/tasks.py +++ b/InvenTree/InvenTree/tasks.py @@ -171,7 +171,7 @@ def update_exchange_rates(): from InvenTree.exchange import InvenTreeExchange from djmoney.contrib.exchange.models import ExchangeBackend, Rate from django.conf import settings - from common.settings import currency_code_default + from common.settings import currency_code_default, currency_codes except AppRegistryNotReady: # Apps not yet loaded! logger.info("Could not perform 'update_exchange_rates' - App registry not ready") @@ -200,7 +200,7 @@ def update_exchange_rates(): backend.update_rates(base_currency=base) # Remove any exchange rates which are not in the provided currencies - Rate.objects.filter(backend="InvenTreeExchange").exclude(currency__in=settings.CURRENCIES).delete() + Rate.objects.filter(backend="InvenTreeExchange").exclude(currency__in=currency_codes()).delete() def send_email(subject, body, recipients, from_email=None): diff --git a/InvenTree/InvenTree/tests.py b/InvenTree/InvenTree/tests.py index b7e5b98c1b..44f907e21a 100644 --- a/InvenTree/InvenTree/tests.py +++ b/InvenTree/InvenTree/tests.py @@ -22,6 +22,7 @@ from decimal import Decimal import InvenTree.tasks from stock.models import StockLocation +from common.settings import currency_codes class ValidatorTest(TestCase): @@ -337,13 +338,11 @@ class CurrencyTests(TestCase): with self.assertRaises(MissingRate): convert_money(Money(100, 'AUD'), 'USD') - currencies = settings.CURRENCIES - InvenTree.tasks.update_exchange_rates() rates = Rate.objects.all() - self.assertEqual(rates.count(), len(currencies)) + self.assertEqual(rates.count(), len(currency_codes())) # Now that we have some exchange rate information, we can perform conversions diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 9a5e7176a1..9ce9e91ee9 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -21,7 +21,7 @@ from django.views.generic import ListView, DetailView, CreateView, FormView, Del from django.views.generic.base import RedirectView, TemplateView from djmoney.contrib.exchange.models import ExchangeBackend, Rate -from common.settings import currency_code_default +from common.settings import currency_code_default, currency_codes from part.models import Part, PartCategory from stock.models import StockLocation, StockItem @@ -822,7 +822,7 @@ class CurrencySettingsView(TemplateView): ctx['settings'] = InvenTreeSetting.objects.all().order_by('key') ctx["base_currency"] = currency_code_default() - ctx["currencies"] = settings.CURRENCIES + ctx["currencies"] = currency_codes ctx["rates"] = Rate.objects.filter(backend="InvenTreeExchange") diff --git a/InvenTree/common/settings.py b/InvenTree/common/settings.py index 4d3b0c7940..de543c2620 100644 --- a/InvenTree/common/settings.py +++ b/InvenTree/common/settings.py @@ -31,6 +31,13 @@ def currency_code_mappings(): return [(a, a) for a in settings.CURRENCIES] +def currency_codes(): + """ + Returns the current currency codes + """ + return [a for a in settings.CURRENCIES] + + def stock_expiry_enabled(): """