2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 20:15:44 +00:00

Merge branch 'master' of https://github.com/inventree/InvenTree into part-import

This commit is contained in:
2021-06-02 00:36:15 +02:00
143 changed files with 53382 additions and 16913 deletions

View File

@ -12,6 +12,8 @@ from django.utils.translation import gettext as _
from InvenTree.forms import HelperForm
from common.settings import currency_code_default
from .files import FileManager
from .models import InvenTreeSetting
@ -180,40 +182,6 @@ class MatchItem(forms.Form):
initial=value,
)
# Optional item selection box
elif col_guess in file_manager.OPTIONAL_MATCH_HEADERS:
# Get item options
item_options = [(option.id, option) for option in row['match_options_' + col_guess]]
# Get item match
item_match = row['match_' + col_guess]
# Set field select box
self.fields[field_name] = forms.ChoiceField(
choices=[('', '-' * 10)] + item_options,
required=False,
widget=forms.Select(attrs={
'class': 'select bomselect',
})
)
# Update select box when match was found
if item_match:
# Update initial value
self.fields[field_name].initial = item_match.id
def clean_nbr(self, number):
""" Clean-up decimal value """
# Check if empty
if not number:
return number
# Check if decimal type
try:
clean_number = Decimal(number)
except InvalidOperation:
clean_number = number
return clean_number.quantize(Decimal(1)) if clean_number == clean_number.to_integral() else clean_number.normalize()
def get_special_field(self, col_guess, row, file_manager):
""" function to be overriden in inherited forms to add specific form settings """
pass

View File

@ -14,11 +14,12 @@ from django.db import models, transaction
from django.db.utils import IntegrityError, OperationalError
from django.conf import settings
import djmoney.settings
from djmoney.models.fields import MoneyField
from djmoney.contrib.exchange.models import convert_money
from djmoney.contrib.exchange.exceptions import MissingRate
from common.settings import currency_code_default
from django.utils.translation import ugettext_lazy as _
from django.core.validators import MinValueValidator, URLValidator
from django.core.exceptions import ValidationError
@ -80,20 +81,6 @@ class InvenTreeSetting(models.Model):
'default': '',
},
'INVENTREE_DEFAULT_CURRENCY': {
'name': _('Default Currency'),
'description': _('Default currency'),
'default': 'USD',
'choices': djmoney.settings.CURRENCY_CHOICES,
},
'CUSTOM_EXCHANGE_RATES': {
'name': _('Custom Exchange Rates'),
'description': _('Enable custom exchange rates'),
'validator': bool,
'default': False,
},
'INVENTREE_DOWNLOAD_FROM_URL': {
'name': _('Download from URL'),
'description': _('Allow download of remote images and files from external URL'),
@ -773,7 +760,7 @@ def get_price(instance, quantity, moq=True, multiples=True, currency=None):
if currency is None:
# Default currency selection
currency = InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')
currency = currency_code_default()
pb_min = None
for pb in instance.price_breaks.all():

View File

@ -7,7 +7,8 @@ from __future__ import unicode_literals
from moneyed import CURRENCIES
from common.models import InvenTreeSetting
import common.models
from django.conf import settings
def currency_code_default():
@ -15,7 +16,7 @@ def currency_code_default():
Returns the default currency code (or USD if not specified)
"""
code = InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')
code = settings.BASE_CURRENCY
if code not in CURRENCIES:
code = 'USD'
@ -28,4 +29,4 @@ def stock_expiry_enabled():
Returns True if the stock expiry feature is enabled
"""
return InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY')
return common.models.InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY')

View File

@ -98,20 +98,15 @@ class SettingsViewTest(TestCase):
Tests for a setting which has choices
"""
setting = InvenTreeSetting.get_setting_object('INVENTREE_DEFAULT_CURRENCY')
setting = InvenTreeSetting.get_setting_object('PURCHASEORDER_REFERENCE_PREFIX')
# Default value!
self.assertEqual(setting.value, 'USD')
self.assertEqual(setting.value, 'PO')
url = self.get_url(setting.pk)
# Try posting an invalid currency option
data, errors = self.post(url, {'value': 'XPQaaa'}, valid=False)
self.assertIsNotNone(errors.get('value'), None)
# Try posting a valid currency option
data, errors = self.post(url, {'value': 'AUD'}, valid=True)
data, errors = self.post(url, {'value': 'Purchase Order'}, valid=True)
def test_binary_values(self):
"""