2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 21:15:41 +00:00

Merge branch 'master' of https://github.com/inventree/InvenTree into homepage-settings

This commit is contained in:
2021-07-23 00:03:21 +02:00
50 changed files with 2692 additions and 177 deletions

View File

@ -53,17 +53,20 @@ class FileManager:
ext = os.path.splitext(file.name)[-1].lower().replace('.', '')
if ext in ['csv', 'tsv', ]:
# These file formats need string decoding
raw_data = file.read().decode('utf-8')
# Reset stream position to beginning of file
file.seek(0)
elif ext in ['xls', 'xlsx', 'json', 'yaml', ]:
raw_data = file.read()
# Reset stream position to beginning of file
file.seek(0)
else:
raise ValidationError(_(f'Unsupported file format: {ext.upper()}'))
try:
if ext in ['csv', 'tsv', ]:
# These file formats need string decoding
raw_data = file.read().decode('utf-8')
# Reset stream position to beginning of file
file.seek(0)
elif ext in ['xls', 'xlsx', 'json', 'yaml', ]:
raw_data = file.read()
# Reset stream position to beginning of file
file.seek(0)
else:
raise ValidationError(_(f'Unsupported file format: {ext.upper()}'))
except UnicodeEncodeError:
raise ValidationError(_('Error reading file (invalid encoding)'))
try:
cleaned_data = tablib.Dataset().load(raw_data, format=ext)

View File

@ -19,8 +19,6 @@ from djmoney.settings import CURRENCY_CHOICES
from djmoney.contrib.exchange.models import convert_money
from djmoney.contrib.exchange.exceptions import MissingRate
import common.settings
from django.utils.translation import ugettext_lazy as _
from django.core.validators import MinValueValidator, URLValidator
from django.core.exceptions import ValidationError
@ -670,6 +668,13 @@ class InvenTreeSetting(BaseInvenTreeSetting):
'validator': bool,
},
'SEARCH_PREVIEW_RESULTS': {
'name': _('Search Preview Results'),
'description': _('Number of results to show in search preview window'),
'default': 10,
'validator': [int, MinValueValidator(1)]
},
'STOCK_ENABLE_EXPIRY': {
'name': _('Stock Expiry'),
'description': _('Enable stock expiry functionality'),
@ -853,6 +858,7 @@ def get_price(instance, quantity, moq=True, multiples=True, currency=None, break
- If MOQ (minimum order quantity) is required, bump quantity
- If order multiples are to be observed, then we need to calculate based on that, too
"""
from common.settings import currency_code_default
if hasattr(instance, break_name):
price_breaks = getattr(instance, break_name).all()
@ -876,7 +882,7 @@ def get_price(instance, quantity, moq=True, multiples=True, currency=None, break
if currency is None:
# Default currency selection
currency = common.settings.currency_code_default()
currency = currency_code_default()
pb_min = None
for pb in price_breaks:

View File

@ -8,15 +8,19 @@ from __future__ import unicode_literals
from moneyed import CURRENCIES
from django.conf import settings
import common.models
def currency_code_default():
"""
Returns the default currency code (or USD if not specified)
"""
from django.db.utils import ProgrammingError
from common.models import InvenTreeSetting
code = common.models.InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')
try:
code = InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')
except ProgrammingError:
# database is not initialized yet
code = ''
if code not in CURRENCIES:
code = 'USD'
@ -42,5 +46,6 @@ def stock_expiry_enabled():
"""
Returns True if the stock expiry feature is enabled
"""
from common.models import InvenTreeSetting
return common.models.InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY')
return InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY')