InvenTree/InvenTree/common/settings.py

52 lines
1.1 KiB
Python
Raw Normal View History

"""
User-configurable settings for the common app
"""
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from moneyed import CURRENCIES
2021-07-01 08:32:07 +00:00
from django.conf import settings
def currency_code_default():
"""
Returns the default currency code (or USD if not specified)
"""
2021-07-19 19:51:04 +00:00
from django.db.utils import ProgrammingError
2021-07-19 18:49:55 +00:00
from common.models import InvenTreeSetting
2021-07-19 19:29:04 +00:00
try:
code = InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')
2022-03-11 23:54:08 +00:00
except ProgrammingError: # pragma: no cover
2021-07-19 19:29:04 +00:00
# database is not initialized yet
code = ''
if code not in CURRENCIES:
2022-03-11 23:54:08 +00:00
code = 'USD' # pragma: no cover
return code
2021-07-01 08:37:16 +00:00
def currency_code_mappings():
2021-07-01 08:32:07 +00:00
"""
Returns the current currency choices
"""
return [(a, CURRENCIES[a].name) for a in settings.CURRENCIES]
2021-07-01 08:32:07 +00:00
2021-07-01 08:41:23 +00:00
def currency_codes():
"""
Returns the current currency codes
"""
return [a for a in settings.CURRENCIES]
def stock_expiry_enabled():
"""
Returns True if the stock expiry feature is enabled
"""
2021-07-19 18:49:55 +00:00
from common.models import InvenTreeSetting
2021-07-19 18:49:55 +00:00
return InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY')