2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-12-20 11:13:28 +00:00

Allow null values for InvenTreeDecimalField (#10948) (#10951)

- Fixes bug related to importing null "rounding_multiple" BOM field

(cherry picked from commit 7920b0e670)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
github-actions[bot]
2025-12-04 07:15:38 +11:00
committed by GitHub
parent 10769ccb04
commit 1a8287824b

View File

@@ -646,6 +646,11 @@ class InvenTreeDecimalField(serializers.FloatField):
def to_internal_value(self, data): def to_internal_value(self, data):
"""Convert to python type.""" """Convert to python type."""
if data in [None, '']:
if self.allow_null:
return None
raise serializers.ValidationError(_('This field may not be null.'))
# Convert the value to a string, and then a decimal # Convert the value to a string, and then a decimal
try: try:
return Decimal(str(data)) return Decimal(str(data))