mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
small code tweaks (#7454)
This commit is contained in:
parent
79ea6897ea
commit
946390a4a3
src/backend/InvenTree
@ -7,6 +7,8 @@ from django.conf import settings
|
|||||||
|
|
||||||
from jinja2 import Environment, select_autoescape
|
from jinja2 import Environment, select_autoescape
|
||||||
|
|
||||||
|
from common.settings import get_global_setting
|
||||||
|
|
||||||
logger = logging.getLogger('inventree')
|
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.
|
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
|
||||||
global _part_full_name_template_string
|
global _part_full_name_template_string
|
||||||
|
|
||||||
template_string = InvenTreeSetting.get_setting(
|
template_string = get_global_setting('PART_NAME_FORMAT', cache=True)
|
||||||
'PART_NAME_FORMAT', backup_value='', cache=True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Skip if the template string has not changed
|
# Skip if the template string has not changed
|
||||||
if (
|
if (
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
Provides URL endpoints for:
|
Provides URL endpoints for:
|
||||||
- Display / Create / Edit / Delete PartCategory
|
- Display / Create / Edit / Delete PartCategory
|
||||||
- Display / Create / Edit / Delete Part
|
- Display / Create / Edit / Delete Part
|
||||||
- Create / Edit / Delete PartAttachment
|
|
||||||
- Display / Create / Edit / Delete SupplierPart
|
- Display / Create / Edit / Delete SupplierPart
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -391,6 +391,31 @@ class StockItemSerializer(InvenTree.serializers.InvenTreeTagModelSerializer):
|
|||||||
"""
|
"""
|
||||||
extra_kwargs = {'use_pack_size': {'write_only': True}}
|
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(
|
part = serializers.PrimaryKeyRelatedField(
|
||||||
queryset=part_models.Part.objects.all(),
|
queryset=part_models.Part.objects.all(),
|
||||||
many=False,
|
many=False,
|
||||||
@ -547,31 +572,6 @@ class StockItemSerializer(InvenTree.serializers.InvenTreeTagModelSerializer):
|
|||||||
|
|
||||||
tags = TagListSerializerField(required=False)
|
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):
|
class SerializeStockItemSerializer(serializers.Serializer):
|
||||||
"""A DRF serializer for "serializing" a StockItem.
|
"""A DRF serializer for "serializing" a StockItem.
|
||||||
|
Loading…
Reference in New Issue
Block a user