From b9f83eefc842afba5a920038f51e66683fb3e120 Mon Sep 17 00:00:00 2001 From: wolflu05 <76838159+wolflu05@users.noreply.github.com> Date: Tue, 16 Aug 2022 13:51:55 +0200 Subject: [PATCH] Feature/icons for PartCategory and StockLocation (#3542) * Added icon to stock location - added `icon` field to `stock_stocklocation` model - added input field to stock location form - added icon to breadcrumb treeview in header - added icon to sub-locations table - added icon to location detail information - added `STOCK_LOCATION_DEFAULT_ICON` setting as default * Added icon to part category - added `icon` field to `part_partcategory` model - added input field to part category form - added icon to breadcrumb treeview in header - added icon to sub-categories table - added icon to category detail information - added `PART_CATEGORY_DEFAULT_ICON` setting as default * Added `blocktrans` to allowed tags in ci check * fix: style * Added `endblocktrans` to allowed tags in ci check * fix: missing `,` in ci check allowed tags script * Removed blocktrans from js and fixed style --- InvenTree/InvenTree/static/css/inventree.css | 5 +++++ InvenTree/common/models.py | 12 ++++++++++++ .../part/migrations/0084_partcategory_icon.py | 18 ++++++++++++++++++ InvenTree/part/models.py | 7 +++++++ InvenTree/part/serializers.py | 2 ++ InvenTree/part/templates/part/category.html | 11 +++++++++-- .../migrations/0083_stocklocation_icon.py | 18 ++++++++++++++++++ InvenTree/stock/models.py | 7 +++++++ InvenTree/stock/serializers.py | 2 ++ InvenTree/stock/templates/stock/location.html | 10 ++++++++-- .../templates/InvenTree/settings/part.html | 2 ++ .../templates/InvenTree/settings/stock.html | 1 + InvenTree/templates/js/dynamic/nav.js | 1 + InvenTree/templates/js/translated/part.js | 11 ++++++++++- InvenTree/templates/js/translated/stock.js | 9 +++++++++ 15 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 InvenTree/part/migrations/0084_partcategory_icon.py create mode 100644 InvenTree/stock/migrations/0083_stocklocation_icon.py diff --git a/InvenTree/InvenTree/static/css/inventree.css b/InvenTree/InvenTree/static/css/inventree.css index 0d6b07e9ff..c6dded3071 100644 --- a/InvenTree/InvenTree/static/css/inventree.css +++ b/InvenTree/InvenTree/static/css/inventree.css @@ -1028,3 +1028,8 @@ a { margin-top: 3px; overflow: hidden; } + +.treeview .node-icon { + margin-left: 0.25rem; + margin-right: 0.25rem; +} diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index a0752e4915..aec2c553f1 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -1070,6 +1070,12 @@ class InvenTreeSetting(BaseInvenTreeSetting): 'validator': InvenTree.validators.validate_part_name_format }, + 'PART_CATEGORY_DEFAULT_ICON': { + 'name': _('Part Category Default Icon'), + 'description': _('Part category default icon (empty means no icon)'), + 'default': '', + }, + 'LABEL_ENABLE': { 'name': _('Enable label printing'), 'description': _('Enable label printing from the web interface'), @@ -1168,6 +1174,12 @@ class InvenTreeSetting(BaseInvenTreeSetting): 'validator': bool, }, + 'STOCK_LOCATION_DEFAULT_ICON': { + 'name': _('Stock Location Default Icon'), + 'description': _('Stock location default icon (empty means no icon)'), + 'default': '', + }, + 'BUILDORDER_REFERENCE_PATTERN': { 'name': _('Build Order Reference Pattern'), 'description': _('Required pattern for generating Build Order reference field'), diff --git a/InvenTree/part/migrations/0084_partcategory_icon.py b/InvenTree/part/migrations/0084_partcategory_icon.py new file mode 100644 index 0000000000..8b92cfaad0 --- /dev/null +++ b/InvenTree/part/migrations/0084_partcategory_icon.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.15 on 2022-08-15 08:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0083_auto_20220731_2357'), + ] + + operations = [ + migrations.AddField( + model_name='partcategory', + name='icon', + field=models.CharField(blank=True, help_text='Icon (optional)', max_length=100, verbose_name='Icon'), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 38319a2e91..95cf3f4405 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -101,6 +101,13 @@ class PartCategory(MetadataMixin, InvenTreeTree): default_keywords = models.CharField(null=True, blank=True, max_length=250, verbose_name=_('Default keywords'), help_text=_('Default keywords for parts in this category')) + icon = models.CharField( + blank=True, + max_length=100, + verbose_name=_("Icon"), + help_text=_("Icon (optional)") + ) + @staticmethod def get_api_url(): """Return the API url associated with the PartCategory model""" diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 71fb7c303e..3c983bfe04 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -75,6 +75,7 @@ class CategorySerializer(InvenTreeModelSerializer): 'pathstring', 'starred', 'url', + 'icon', ] @@ -88,6 +89,7 @@ class CategoryTree(InvenTreeModelSerializer): 'pk', 'name', 'parent', + 'icon', ] diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index d31fe08321..6d55397007 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -1,6 +1,7 @@ {% extends "part/part_app_base.html" %} {% load static %} {% load i18n %} +{% load inventree_extras %} {% block sidebar %} {% include 'part/category_sidebar.html' %} @@ -12,7 +13,12 @@ {% block heading %} {% if category %} -{% trans "Part Category" %}: {{ category.name }} +{% trans "Part Category" %}: +{% settings_value "PART_CATEGORY_DEFAULT_ICON" as default_icon %} +{% if category.icon or default_icon %} + +{% endif %} +{{ category.name }} {% else %} {% trans "Parts" %} {% endif %} @@ -288,7 +294,8 @@ node.href = `/part/category/${node.pk}/`; return node; - } + }, + defaultIcon: global_settings.PART_CATEGORY_DEFAULT_ICON, }); onPanelLoad('subcategories', function() { diff --git a/InvenTree/stock/migrations/0083_stocklocation_icon.py b/InvenTree/stock/migrations/0083_stocklocation_icon.py new file mode 100644 index 0000000000..7b19658157 --- /dev/null +++ b/InvenTree/stock/migrations/0083_stocklocation_icon.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.15 on 2022-08-15 08:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0082_alter_stockitem_link'), + ] + + operations = [ + migrations.AddField( + model_name='stocklocation', + name='icon', + field=models.CharField(blank=True, help_text='Icon (optional)', max_length=100, verbose_name='Icon'), + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index b23e72117d..d015b09aae 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -78,6 +78,13 @@ class StockLocation(MetadataMixin, InvenTreeTree): """Return API url.""" return reverse('api-location-list') + icon = models.CharField( + blank=True, + max_length=100, + verbose_name=_("Icon"), + help_text=_("Icon (optional)") + ) + owner = models.ForeignKey(Owner, on_delete=models.SET_NULL, blank=True, null=True, verbose_name=_('Owner'), help_text=_('Select Owner'), diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index 31df615989..3690de5516 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -570,6 +570,7 @@ class LocationTreeSerializer(InvenTree.serializers.InvenTreeModelSerializer): 'pk', 'name', 'parent', + 'icon', ] @@ -607,6 +608,7 @@ class LocationSerializer(InvenTree.serializers.InvenTreeModelSerializer): 'pathstring', 'items', 'owner', + 'icon', ] diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 5fd8312b2f..13f153fc65 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -14,7 +14,12 @@ {% block heading %} {% if location %} -{% trans "Stock Location" %}: {{ location.name }} +{% trans "Stock Location" %}: +{% settings_value "STOCK_LOCATION_DEFAULT_ICON" as default_icon %} +{% if location.icon or default_icon %} + +{% endif %} +{{ location.name }} {% else %} {% trans "Stock" %} {% endif %} @@ -380,7 +385,8 @@ node.href = `/stock/location/${node.pk}/`; return node; - } + }, + defaultIcon: global_settings.STOCK_LOCATION_DEFAULT_ICON, }); {% endblock %} diff --git a/InvenTree/templates/InvenTree/settings/part.html b/InvenTree/templates/InvenTree/settings/part.html index 1004113dc6..aea734d5a4 100644 --- a/InvenTree/templates/InvenTree/settings/part.html +++ b/InvenTree/templates/InvenTree/settings/part.html @@ -36,6 +36,8 @@