diff --git a/InvenTree/InvenTree/conversion.py b/InvenTree/InvenTree/conversion.py index 8637ae382b..67e18dc0e7 100644 --- a/InvenTree/InvenTree/conversion.py +++ b/InvenTree/InvenTree/conversion.py @@ -91,7 +91,7 @@ def convert_physical_value(value: str, unit: str = None): # At this point we *should* have a valid pint value # To double check, look at the maginitude float(val.magnitude) - except (TypeError, ValueError): + except (TypeError, ValueError, AttributeError): error = _('Provided value is not a valid number') except (pint.errors.UndefinedUnitError, pint.errors.DefinitionSyntaxError): error = _('Provided value has an invalid unit') diff --git a/InvenTree/InvenTree/tests.py b/InvenTree/InvenTree/tests.py index 83c340e7e5..a68f7c4739 100644 --- a/InvenTree/InvenTree/tests.py +++ b/InvenTree/InvenTree/tests.py @@ -56,6 +56,23 @@ class ConversionTest(TestCase): q = InvenTree.conversion.convert_physical_value(val).to_base_units() self.assertEqual(q.magnitude, expected) + def test_invalid_values(self): + """Test conversion of invalid inputs""" + + inputs = [ + '-', + ';;', + '-x', + '?', + '--', + '+', + '++', + ] + + for val in inputs: + with self.assertRaises(ValidationError): + InvenTree.conversion.convert_physical_value(val) + class ValidatorTest(TestCase): """Simple tests for custom field validators.""" diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index ebce845a7c..bba41ab980 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -1404,6 +1404,7 @@ function createPartParameter(part_id, options={}) { function editPartParameter(param_id, options={}) { options.fields = partParameterFields(); options.title = '{% trans "Edit Parameter" %}'; + options.focus = 'data'; options.processBeforeUpload = function(data) { // Convert data to string