2020-11-12 00:02:10 +00:00
|
|
|
"""
|
|
|
|
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
|
2020-11-12 00:02:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2020-11-12 00:02:10 +00:00
|
|
|
|
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 = ''
|
2020-11-12 00:02:10 +00:00
|
|
|
|
|
|
|
if code not in CURRENCIES:
|
2022-03-11 23:54:08 +00:00
|
|
|
code = 'USD' # pragma: no cover
|
2021-05-06 10:11:38 +00:00
|
|
|
|
2020-11-12 00:02:10 +00:00
|
|
|
return code
|
2021-01-04 21:50:07 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
2021-07-02 18:02:15 +00:00
|
|
|
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]
|
|
|
|
|
|
|
|
|
2021-01-04 21:50:07 +00:00
|
|
|
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-01-04 21:50:07 +00:00
|
|
|
|
2021-07-19 18:49:55 +00:00
|
|
|
return InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY')
|