2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-09 16:58:49 +00:00

Allow settings value to be nullified ()

* Allow settings value to be nullified

* Additional null check

* Bump API version

* Fix for unit test
This commit is contained in:
Oliver 2024-11-30 15:30:28 +11:00 committed by GitHub
parent 327884ca26
commit 3149ae79ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 4 deletions
src
backend/InvenTree
frontend/src/components/settings

@ -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."""

@ -68,6 +68,7 @@ export function SettingList({
fields: {
value: {
field_type: fieldType,
required: setting?.required ?? false,
label: setting?.name,
description: setting?.description,
api_url: setting?.api_url ?? '',