mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 12:05:53 +00:00
Allow settings value to be nullified (#8596)
* Allow settings value to be nullified * Additional null check * Bump API version * Fix for unit test
This commit is contained in:
@ -1,13 +1,16 @@
|
||||
"""InvenTree API version information."""
|
||||
|
||||
# InvenTree API version
|
||||
INVENTREE_API_VERSION = 290
|
||||
INVENTREE_API_VERSION = 291
|
||||
|
||||
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||
|
||||
|
||||
INVENTREE_API_TEXT = """
|
||||
|
||||
v291 - 2024-11-30 : https://github.com/inventree/InvenTree/pull/8596
|
||||
- Allow null / empty values for plugin settings
|
||||
|
||||
v290 - 2024-11-29 : https://github.com/inventree/InvenTree/pull/8590
|
||||
- Adds "quantity" field to ReturnOrderLineItem model and API
|
||||
|
||||
|
@ -41,11 +41,19 @@ class SettingsValueField(serializers.Field):
|
||||
|
||||
Protected settings are returned as '***'
|
||||
"""
|
||||
return '***' if instance.protected else str(instance.value)
|
||||
if instance.protected:
|
||||
return '***'
|
||||
elif instance.value is None:
|
||||
return ''
|
||||
else:
|
||||
return str(instance.value)
|
||||
|
||||
def to_internal_value(self, data):
|
||||
"""Return the internal value of the setting."""
|
||||
return str(data)
|
||||
if data is None:
|
||||
return ''
|
||||
else:
|
||||
return str(data)
|
||||
|
||||
|
||||
class SettingsSerializer(InvenTreeModelSerializer):
|
||||
@ -65,7 +73,13 @@ class SettingsSerializer(InvenTreeModelSerializer):
|
||||
|
||||
api_url = serializers.CharField(read_only=True)
|
||||
|
||||
value = SettingsValueField()
|
||||
value = SettingsValueField(allow_null=True)
|
||||
|
||||
def validate_value(self, value):
|
||||
"""Validate the value of the setting."""
|
||||
if value is None:
|
||||
return ''
|
||||
return str(value)
|
||||
|
||||
units = serializers.CharField(read_only=True)
|
||||
|
||||
@ -185,6 +199,12 @@ class GenericReferencedSettingSerializer(SettingsSerializer):
|
||||
# resume operations
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def validate_value(self, value):
|
||||
"""Validate the value of the setting."""
|
||||
if value is None:
|
||||
return ''
|
||||
return str(value)
|
||||
|
||||
|
||||
class NotificationMessageSerializer(InvenTreeModelSerializer):
|
||||
"""Serializer for the InvenTreeUserSetting model."""
|
||||
|
Reference in New Issue
Block a user