mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
using functions for currency codes
This commit is contained in:
parent
983255a05e
commit
951e8910ba
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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():
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user