2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 03:26:45 +00:00

Allow custom icons to be cleared (#9185)

* Allow custom icons to be cleared

- Closes https://github.com/inventree/InvenTree/issues/9182

* Bump API version

* Update unit test

* Loosen test requirements
This commit is contained in:
Oliver 2025-02-26 13:25:44 +11:00 committed by GitHub
parent 94c2157d3c
commit 3940544a70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 69 additions and 5 deletions

View File

@ -1,13 +1,17 @@
"""InvenTree API version information."""
# InvenTree API version
INVENTREE_API_VERSION = 315
INVENTREE_API_VERSION = 316
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """
v316 - 2025-02-26 : https://github.com/inventree/InvenTree/pull/9185
- Allow 'icon' field to be nullified in the PartCategory API
- Allow 'custom_icon' field to be nullified in the StockLocation API
v315 - 2025-02-22 : https://github.com/inventree/InvenTree/pull/9150
- Remove outdated 'url' field from some API endpoints

View File

@ -0,0 +1,27 @@
# Generated by Django 4.2.19 on 2025-02-25 22:14
import common.icons
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("part", "0132_partparametertemplate_selectionlist"),
]
operations = [
migrations.AlterField(
model_name="partcategory",
name="_icon",
field=models.CharField(
blank=True,
db_column="icon",
help_text="Icon (optional)",
max_length=100,
null=True,
validators=[common.icons.validate_icon],
verbose_name="Icon",
),
),
]

View File

@ -128,6 +128,7 @@ class PartCategory(InvenTree.models.InvenTreeTree):
_icon = models.CharField(
blank=True,
null=True,
max_length=100,
verbose_name=_('Icon'),
help_text=_('Icon (optional)'),

View File

@ -136,7 +136,11 @@ class CategorySerializer(
)
icon = serializers.CharField(
required=False, allow_blank=True, help_text=_('Icon (optional)'), max_length=100
required=False,
allow_blank=True,
allow_null=True,
help_text=_('Icon (optional)'),
max_length=100,
)
parent_default_location = serializers.IntegerField(read_only=True)

View File

@ -419,7 +419,7 @@ class CategoryTest(TestCase):
"""Test the category icon."""
# No default icon set
cat = PartCategory.objects.create(name='Test Category')
self.assertEqual(cat.icon, '')
self.assertIn(cat.icon, ['', None])
# Set a default icon
InvenTreeSetting.set_setting('PART_CATEGORY_DEFAULT_ICON', 'ti:package:outline')
@ -428,7 +428,7 @@ class CategoryTest(TestCase):
# Set custom icon to default icon and assert that it does not get written to the database
cat.icon = 'ti:package:outline'
cat.save()
self.assertEqual(cat._icon, '')
self.assertIn(cat._icon, ['', None])
# Set a different custom icon and assert that it takes precedence
cat.icon = 'ti:tag:outline'
@ -439,4 +439,4 @@ class CategoryTest(TestCase):
# Test that the icon can be set to None again
cat.icon = ''
cat.save()
self.assertEqual(cat.icon, '')
self.assertIn(cat.icon, ['', None])

View File

@ -0,0 +1,27 @@
# Generated by Django 4.2.19 on 2025-02-25 22:14
import common.icons
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("stock", "0113_stockitem_status_custom_key_and_more"),
]
operations = [
migrations.AlterField(
model_name="stocklocation",
name="custom_icon",
field=models.CharField(
blank=True,
db_column="icon",
help_text="Icon (optional)",
max_length=100,
null=True,
validators=[common.icons.validate_icon],
verbose_name="Icon",
),
),
]

View File

@ -171,6 +171,7 @@ class StockLocation(
custom_icon = models.CharField(
blank=True,
null=True,
max_length=100,
verbose_name=_('Icon'),
help_text=_('Icon (optional)'),