small code tweaks (#7454)

This commit is contained in:
Oliver 2024-06-16 23:38:33 +10:00 committed by GitHub
parent 79ea6897ea
commit 946390a4a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 31 deletions

View File

@ -7,6 +7,8 @@ from django.conf import settings
from jinja2 import Environment, select_autoescape
from common.settings import get_global_setting
logger = logging.getLogger('inventree')
@ -20,14 +22,10 @@ def compile_full_name_template(*args, **kwargs):
This function is called whenever the 'PART_NAME_FORMAT' setting is changed.
"""
from common.models import InvenTreeSetting
global _part_full_name_template
global _part_full_name_template_string
template_string = InvenTreeSetting.get_setting(
'PART_NAME_FORMAT', backup_value='', cache=True
)
template_string = get_global_setting('PART_NAME_FORMAT', cache=True)
# Skip if the template string has not changed
if (

View File

@ -3,7 +3,6 @@
Provides URL endpoints for:
- Display / Create / Edit / Delete PartCategory
- Display / Create / Edit / Delete Part
- Create / Edit / Delete PartAttachment
- Display / Create / Edit / Delete SupplierPart
"""

View File

@ -391,6 +391,31 @@ class StockItemSerializer(InvenTree.serializers.InvenTreeTagModelSerializer):
"""
extra_kwargs = {'use_pack_size': {'write_only': True}}
def __init__(self, *args, **kwargs):
"""Add detail fields."""
part_detail = kwargs.pop('part_detail', False)
location_detail = kwargs.pop('location_detail', False)
supplier_part_detail = kwargs.pop('supplier_part_detail', False)
tests = kwargs.pop('tests', False)
path_detail = kwargs.pop('path_detail', False)
super(StockItemSerializer, self).__init__(*args, **kwargs)
if not part_detail:
self.fields.pop('part_detail')
if not location_detail:
self.fields.pop('location_detail')
if not supplier_part_detail:
self.fields.pop('supplier_part_detail')
if not tests:
self.fields.pop('tests')
if not path_detail:
self.fields.pop('location_path')
part = serializers.PrimaryKeyRelatedField(
queryset=part_models.Part.objects.all(),
many=False,
@ -547,31 +572,6 @@ class StockItemSerializer(InvenTree.serializers.InvenTreeTagModelSerializer):
tags = TagListSerializerField(required=False)
def __init__(self, *args, **kwargs):
"""Add detail fields."""
part_detail = kwargs.pop('part_detail', False)
location_detail = kwargs.pop('location_detail', False)
supplier_part_detail = kwargs.pop('supplier_part_detail', False)
tests = kwargs.pop('tests', False)
path_detail = kwargs.pop('path_detail', False)
super(StockItemSerializer, self).__init__(*args, **kwargs)
if not part_detail:
self.fields.pop('part_detail')
if not location_detail:
self.fields.pop('location_detail')
if not supplier_part_detail:
self.fields.pop('supplier_part_detail')
if not tests:
self.fields.pop('tests')
if not path_detail:
self.fields.pop('location_path')
class SerializeStockItemSerializer(serializers.Serializer):
"""A DRF serializer for "serializing" a StockItem.