mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Feet and inches (#6674)
* Conversion: Handle feet and inches - Support ' for feet - Support " for inches * Add unit test * Doc updates
This commit is contained in:
		| @@ -165,6 +165,13 @@ def convert_physical_value(value: str, unit: str = None, strip_units=True): | ||||
|     value = str(value).strip() if value else '' | ||||
|     unit = str(unit).strip() if unit else '' | ||||
|  | ||||
|     # Handle imperial length measurements | ||||
|     if value.count("'") == 1 and value.endswith("'"): | ||||
|         value = value.replace("'", ' feet') | ||||
|  | ||||
|     if value.count('"') == 1 and value.endswith('"'): | ||||
|         value = value.replace('"', ' inches') | ||||
|  | ||||
|     # Error on blank values | ||||
|     if not value: | ||||
|         raise ValidationError(_('No value provided')) | ||||
|   | ||||
| @@ -138,6 +138,24 @@ class ConversionTest(TestCase): | ||||
|             q = InvenTree.conversion.convert_physical_value(val, 'W', strip_units=False) | ||||
|             self.assertAlmostEqual(float(q.magnitude), expected, places=2) | ||||
|  | ||||
|     def test_imperial_lengths(self): | ||||
|         """Test support of imperial length measurements.""" | ||||
|         tests = [ | ||||
|             ('1 inch', 'mm', 25.4), | ||||
|             ('1 "', 'mm', 25.4), | ||||
|             ('2 "', 'inches', 2), | ||||
|             ('3 feet', 'inches', 36), | ||||
|             ("3'", 'inches', 36), | ||||
|             ("7 '", 'feet', 7), | ||||
|         ] | ||||
|  | ||||
|         for val, unit, expected in tests: | ||||
|             output = InvenTree.conversion.convert_physical_value( | ||||
|                 val, unit, strip_units=True | ||||
|             ) | ||||
|  | ||||
|             self.assertAlmostEqual(output, expected, 3) | ||||
|  | ||||
|     def test_dimensionless_units(self): | ||||
|         """Tests for 'dimensionless' unit quantities.""" | ||||
|         # Test some dimensionless units | ||||
|   | ||||
		Reference in New Issue
	
	Block a user