mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Adds a new custom serializer field - InvenTreeDecimalField
- Fixes a number of problems with using FloatField
This commit is contained in:
		| @@ -296,3 +296,17 @@ class InvenTreeImageSerializerField(serializers.ImageField): | ||||
|             return None | ||||
|  | ||||
|         return os.path.join(str(settings.MEDIA_URL), str(value)) | ||||
|  | ||||
|  | ||||
| class InvenTreeDecimalField(serializers.FloatField): | ||||
|     """ | ||||
|     Custom serializer for decimal fields. Solves the following issues: | ||||
|  | ||||
|     - The normal DRF DecimalField renders values with trailing zeros | ||||
|     - Using a FloatField can result in rounding issues: https://code.djangoproject.com/ticket/30290 | ||||
|     """ | ||||
|  | ||||
|     def to_internal_value(self, data): | ||||
|  | ||||
|         # Convert the value to a string, and then a decimal | ||||
|         return Decimal(str(data)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user