Skip to content

Commit

Permalink
Allow custom icons to be cleared (#9185)
Browse files Browse the repository at this point in the history
* Allow custom icons to be cleared

- Closes #9182

* Bump API version

* Update unit test

* Loosen test requirements
  • Loading branch information
SchrodingersGat authored Feb 26, 2025
1 parent 94c2157 commit 3940544
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/backend/InvenTree/InvenTree/api_version.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
1 change: 1 addition & 0 deletions src/backend/InvenTree/part/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def delete(self, *args, **kwargs):

_icon = models.CharField(
blank=True,
null=True,
max_length=100,
verbose_name=_('Icon'),
help_text=_('Icon (optional)'),
Expand Down
6 changes: 5 additions & 1 deletion src/backend/InvenTree/part/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ def annotate_queryset(queryset):
)

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)
Expand Down
6 changes: 3 additions & 3 deletions src/backend/InvenTree/part/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def test_icon(self):
"""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')
Expand All @@ -428,7 +428,7 @@ def test_icon(self):
# 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'
Expand All @@ -439,4 +439,4 @@ def test_icon(self):
# Test that the icon can be set to None again
cat.icon = ''
cat.save()
self.assertEqual(cat.icon, '')
self.assertIn(cat.icon, ['', None])
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
1 change: 1 addition & 0 deletions src/backend/InvenTree/stock/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def report_context(self):

custom_icon = models.CharField(
blank=True,
null=True,
max_length=100,
verbose_name=_('Icon'),
help_text=_('Icon (optional)'),
Expand Down

0 comments on commit 3940544

Please sign in to comment.