mirror of
https://github.com/inventree/InvenTree.git
synced 2025-10-25 18:37:38 +00:00
more adoption
This commit is contained in:
@@ -38,6 +38,7 @@ from InvenTree.serializers import (
|
|||||||
InvenTreeDecimalField,
|
InvenTreeDecimalField,
|
||||||
InvenTreeModelSerializer,
|
InvenTreeModelSerializer,
|
||||||
NotesFieldMixin,
|
NotesFieldMixin,
|
||||||
|
can_filter,
|
||||||
)
|
)
|
||||||
from stock.generators import generate_batch_code
|
from stock.generators import generate_batch_code
|
||||||
from stock.models import StockItem, StockLocation
|
from stock.models import StockItem, StockLocation
|
||||||
@@ -117,8 +118,9 @@ class BuildSerializer(
|
|||||||
|
|
||||||
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
||||||
|
|
||||||
part_detail = part_serializers.PartBriefSerializer(
|
part_detail = can_filter(
|
||||||
source='part', many=False, read_only=True
|
part_serializers.PartBriefSerializer(source='part', many=False, read_only=True),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
part_name = serializers.CharField(
|
part_name = serializers.CharField(
|
||||||
@@ -171,7 +173,6 @@ class BuildSerializer(
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Determine if extra serializer fields are required."""
|
"""Determine if extra serializer fields are required."""
|
||||||
part_detail = kwargs.pop('part_detail', True)
|
|
||||||
user_detail = kwargs.pop('user_detail', True)
|
user_detail = kwargs.pop('user_detail', True)
|
||||||
project_code_detail = kwargs.pop('project_code_detail', True)
|
project_code_detail = kwargs.pop('project_code_detail', True)
|
||||||
|
|
||||||
@@ -182,13 +183,12 @@ class BuildSerializer(
|
|||||||
if isGeneratingSchema():
|
if isGeneratingSchema():
|
||||||
return
|
return
|
||||||
|
|
||||||
if not part_detail:
|
# TODO INVE-T1 support complex filters
|
||||||
self.fields.pop('part_detail', None)
|
|
||||||
|
|
||||||
if not user_detail:
|
if not user_detail:
|
||||||
self.fields.pop('issued_by_detail', None)
|
self.fields.pop('issued_by_detail', None)
|
||||||
self.fields.pop('responsible_detail', None)
|
self.fields.pop('responsible_detail', None)
|
||||||
|
|
||||||
|
# TODO INVE-T1 support complex filters
|
||||||
if not project_code_detail:
|
if not project_code_detail:
|
||||||
self.fields.pop('project_code', None)
|
self.fields.pop('project_code', None)
|
||||||
self.fields.pop('project_code_label', None)
|
self.fields.pop('project_code_label', None)
|
||||||
@@ -1192,28 +1192,17 @@ class BuildItemSerializer(DataImportExportSerializerMixin, InvenTreeModelSeriali
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Determine which extra details fields should be included."""
|
"""Determine which extra details fields should be included."""
|
||||||
part_detail = kwargs.pop('part_detail', True)
|
|
||||||
location_detail = kwargs.pop('location_detail', True)
|
|
||||||
stock_detail = kwargs.pop('stock_detail', True)
|
stock_detail = kwargs.pop('stock_detail', True)
|
||||||
build_detail = kwargs.pop('build_detail', True)
|
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
if isGeneratingSchema():
|
if isGeneratingSchema():
|
||||||
return
|
return
|
||||||
|
|
||||||
if not part_detail:
|
# TODO INVE-T1 support complex filters
|
||||||
self.fields.pop('part_detail', None)
|
|
||||||
|
|
||||||
if not location_detail:
|
|
||||||
self.fields.pop('location_detail', None)
|
|
||||||
|
|
||||||
if not stock_detail:
|
if not stock_detail:
|
||||||
self.fields.pop('stock_item_detail', None)
|
self.fields.pop('stock_item_detail', None)
|
||||||
|
|
||||||
if not build_detail:
|
|
||||||
self.fields.pop('build_detail', None)
|
|
||||||
|
|
||||||
# Export-only fields
|
# Export-only fields
|
||||||
bom_reference = serializers.CharField(
|
bom_reference = serializers.CharField(
|
||||||
source='build_line.bom_item.reference', label=_('BOM Reference'), read_only=True
|
source='build_line.bom_item.reference', label=_('BOM Reference'), read_only=True
|
||||||
@@ -1239,13 +1228,16 @@ class BuildItemSerializer(DataImportExportSerializerMixin, InvenTreeModelSeriali
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Extra (optional) detail fields
|
# Extra (optional) detail fields
|
||||||
part_detail = part_serializers.PartBriefSerializer(
|
part_detail = can_filter(
|
||||||
|
part_serializers.PartBriefSerializer(
|
||||||
label=_('Part'),
|
label=_('Part'),
|
||||||
source='stock_item.part',
|
source='stock_item.part',
|
||||||
many=False,
|
many=False,
|
||||||
read_only=True,
|
read_only=True,
|
||||||
allow_null=True,
|
allow_null=True,
|
||||||
pricing=False,
|
pricing=False,
|
||||||
|
),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
stock_item_detail = StockItemSerializer(
|
stock_item_detail = StockItemSerializer(
|
||||||
@@ -1263,19 +1255,25 @@ class BuildItemSerializer(DataImportExportSerializerMixin, InvenTreeModelSeriali
|
|||||||
label=_('Location'), source='stock_item.location', many=False, read_only=True
|
label=_('Location'), source='stock_item.location', many=False, read_only=True
|
||||||
)
|
)
|
||||||
|
|
||||||
location_detail = LocationBriefSerializer(
|
location_detail = can_filter(
|
||||||
|
LocationBriefSerializer(
|
||||||
label=_('Location'),
|
label=_('Location'),
|
||||||
source='stock_item.location',
|
source='stock_item.location',
|
||||||
read_only=True,
|
read_only=True,
|
||||||
allow_null=True,
|
allow_null=True,
|
||||||
|
),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
build_detail = BuildSerializer(
|
build_detail = can_filter(
|
||||||
|
BuildSerializer(
|
||||||
label=_('Build'),
|
label=_('Build'),
|
||||||
source='build_line.build',
|
source='build_line.build',
|
||||||
many=False,
|
many=False,
|
||||||
read_only=True,
|
read_only=True,
|
||||||
allow_null=True,
|
allow_null=True,
|
||||||
|
),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
supplier_part_detail = company.serializers.SupplierPartSerializer(
|
supplier_part_detail = company.serializers.SupplierPartSerializer(
|
||||||
@@ -1350,35 +1348,6 @@ class BuildLineSerializer(DataImportExportSerializerMixin, InvenTreeModelSeriali
|
|||||||
|
|
||||||
read_only_fields = ['build', 'bom_item', 'allocations']
|
read_only_fields = ['build', 'bom_item', 'allocations']
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
"""Determine which extra details fields should be included."""
|
|
||||||
part_detail = kwargs.pop('part_detail', True)
|
|
||||||
assembly_detail = kwargs.pop('assembly_detail', True)
|
|
||||||
bom_item_detail = kwargs.pop('bom_item_detail', True)
|
|
||||||
build_detail = kwargs.pop('build_detail', True)
|
|
||||||
allocations = kwargs.pop('allocations', True)
|
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
if isGeneratingSchema():
|
|
||||||
return
|
|
||||||
|
|
||||||
if not bom_item_detail:
|
|
||||||
self.fields.pop('bom_item_detail', None)
|
|
||||||
|
|
||||||
if not part_detail:
|
|
||||||
self.fields.pop('part_detail', None)
|
|
||||||
self.fields.pop('part_category_name', None)
|
|
||||||
|
|
||||||
if not build_detail:
|
|
||||||
self.fields.pop('build_detail', None)
|
|
||||||
|
|
||||||
if not allocations:
|
|
||||||
self.fields.pop('allocations', None)
|
|
||||||
|
|
||||||
if not assembly_detail:
|
|
||||||
self.fields.pop('assembly_detail', None)
|
|
||||||
|
|
||||||
# Build info fields
|
# Build info fields
|
||||||
build_reference = serializers.CharField(
|
build_reference = serializers.CharField(
|
||||||
source='build.reference', label=_('Build Reference'), read_only=True
|
source='build.reference', label=_('Build Reference'), read_only=True
|
||||||
@@ -1395,7 +1364,9 @@ class BuildLineSerializer(DataImportExportSerializerMixin, InvenTreeModelSeriali
|
|||||||
read_only=True,
|
read_only=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
allocations = BuildItemSerializer(many=True, read_only=True, build_detail=False)
|
allocations = can_filter(
|
||||||
|
BuildItemSerializer(many=True, read_only=True, build_detail=False), True
|
||||||
|
)
|
||||||
|
|
||||||
# BOM item info fields
|
# BOM item info fields
|
||||||
reference = serializers.CharField(
|
reference = serializers.CharField(
|
||||||
@@ -1426,7 +1397,8 @@ class BuildLineSerializer(DataImportExportSerializerMixin, InvenTreeModelSeriali
|
|||||||
bom_item = serializers.PrimaryKeyRelatedField(label=_('BOM Item'), read_only=True)
|
bom_item = serializers.PrimaryKeyRelatedField(label=_('BOM Item'), read_only=True)
|
||||||
|
|
||||||
# Foreign key fields
|
# Foreign key fields
|
||||||
bom_item_detail = part_serializers.BomItemSerializer(
|
bom_item_detail = can_filter(
|
||||||
|
part_serializers.BomItemSerializer(
|
||||||
label=_('BOM Item'),
|
label=_('BOM Item'),
|
||||||
source='bom_item',
|
source='bom_item',
|
||||||
many=False,
|
many=False,
|
||||||
@@ -1436,26 +1408,35 @@ class BuildLineSerializer(DataImportExportSerializerMixin, InvenTreeModelSeriali
|
|||||||
sub_part_detail=False,
|
sub_part_detail=False,
|
||||||
part_detail=False,
|
part_detail=False,
|
||||||
can_build=False,
|
can_build=False,
|
||||||
|
),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assembly_detail = part_serializers.PartBriefSerializer(
|
assembly_detail = can_filter(
|
||||||
|
part_serializers.PartBriefSerializer(
|
||||||
label=_('Assembly'),
|
label=_('Assembly'),
|
||||||
source='bom_item.part',
|
source='bom_item.part',
|
||||||
many=False,
|
many=False,
|
||||||
read_only=True,
|
read_only=True,
|
||||||
allow_null=True,
|
allow_null=True,
|
||||||
pricing=False,
|
pricing=False,
|
||||||
|
),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
part_detail = part_serializers.PartBriefSerializer(
|
part_detail = can_filter(
|
||||||
|
part_serializers.PartBriefSerializer(
|
||||||
label=_('Part'),
|
label=_('Part'),
|
||||||
source='bom_item.sub_part',
|
source='bom_item.sub_part',
|
||||||
many=False,
|
many=False,
|
||||||
read_only=True,
|
read_only=True,
|
||||||
pricing=False,
|
pricing=False,
|
||||||
|
),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
build_detail = BuildSerializer(
|
build_detail = can_filter(
|
||||||
|
BuildSerializer(
|
||||||
label=_('Build'),
|
label=_('Build'),
|
||||||
source='build',
|
source='build',
|
||||||
many=False,
|
many=False,
|
||||||
@@ -1464,6 +1445,8 @@ class BuildLineSerializer(DataImportExportSerializerMixin, InvenTreeModelSeriali
|
|||||||
part_detail=False,
|
part_detail=False,
|
||||||
user_detail=False,
|
user_detail=False,
|
||||||
project_code_detail=False,
|
project_code_detail=False,
|
||||||
|
),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Annotated (calculated) fields
|
# Annotated (calculated) fields
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ from InvenTree.serializers import (
|
|||||||
InvenTreeTagModelSerializer,
|
InvenTreeTagModelSerializer,
|
||||||
NotesFieldMixin,
|
NotesFieldMixin,
|
||||||
RemoteImageMixin,
|
RemoteImageMixin,
|
||||||
|
can_filter,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
@@ -275,8 +276,6 @@ class ManufacturerPartSerializer(
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize this serializer with extra detail fields as required."""
|
"""Initialize this serializer with extra detail fields as required."""
|
||||||
part_detail = kwargs.pop('part_detail', True)
|
|
||||||
manufacturer_detail = kwargs.pop('manufacturer_detail', True)
|
|
||||||
prettify = kwargs.pop('pretty', False)
|
prettify = kwargs.pop('pretty', False)
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@@ -284,21 +283,22 @@ class ManufacturerPartSerializer(
|
|||||||
if isGeneratingSchema():
|
if isGeneratingSchema():
|
||||||
return
|
return
|
||||||
|
|
||||||
if part_detail is not True:
|
# TODO INVE-T1 support complex filters
|
||||||
self.fields.pop('part_detail', None)
|
|
||||||
|
|
||||||
if manufacturer_detail is not True:
|
|
||||||
self.fields.pop('manufacturer_detail', None)
|
|
||||||
|
|
||||||
if prettify is not True:
|
if prettify is not True:
|
||||||
self.fields.pop('pretty_name', None)
|
self.fields.pop('pretty_name', None)
|
||||||
|
|
||||||
part_detail = part_serializers.PartBriefSerializer(
|
part_detail = can_filter(
|
||||||
|
part_serializers.PartBriefSerializer(
|
||||||
source='part', many=False, read_only=True, allow_null=True
|
source='part', many=False, read_only=True, allow_null=True
|
||||||
|
),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
manufacturer_detail = CompanyBriefSerializer(
|
manufacturer_detail = can_filter(
|
||||||
|
CompanyBriefSerializer(
|
||||||
source='manufacturer', many=False, read_only=True, allow_null=True
|
source='manufacturer', many=False, read_only=True, allow_null=True
|
||||||
|
),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
pretty_name = serializers.CharField(read_only=True, allow_null=True)
|
pretty_name = serializers.CharField(read_only=True, allow_null=True)
|
||||||
@@ -334,6 +334,7 @@ class ManufacturerPartParameterSerializer(
|
|||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# TODO INVE-T1 support complex filters
|
||||||
if not man_detail and not isGeneratingSchema():
|
if not man_detail and not isGeneratingSchema():
|
||||||
self.fields.pop('manufacturer_part_detail', None)
|
self.fields.pop('manufacturer_part_detail', None)
|
||||||
|
|
||||||
@@ -402,13 +403,11 @@ class SupplierPartSerializer(
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize this serializer with extra detail fields as required."""
|
"""Initialize this serializer with extra detail fields as required."""
|
||||||
# Check if 'available' quantity was supplied
|
# Check if 'available' quantity was supplied
|
||||||
|
|
||||||
self.has_available_quantity = 'available' in kwargs.get('data', {})
|
self.has_available_quantity = 'available' in kwargs.get('data', {})
|
||||||
|
|
||||||
|
# TODO INVE-T1 support complex filters
|
||||||
brief = kwargs.pop('brief', False)
|
brief = kwargs.pop('brief', False)
|
||||||
|
|
||||||
detail_default = not brief
|
detail_default = not brief
|
||||||
|
|
||||||
part_detail = kwargs.pop('part_detail', detail_default)
|
part_detail = kwargs.pop('part_detail', detail_default)
|
||||||
supplier_detail = kwargs.pop('supplier_detail', detail_default)
|
supplier_detail = kwargs.pop('supplier_detail', detail_default)
|
||||||
manufacturer_detail = kwargs.pop('manufacturer_detail', detail_default)
|
manufacturer_detail = kwargs.pop('manufacturer_detail', detail_default)
|
||||||
@@ -563,22 +562,6 @@ class SupplierPriceBreakSerializer(
|
|||||||
'updated',
|
'updated',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
"""Initialize this serializer with extra fields as required."""
|
|
||||||
supplier_detail = kwargs.pop('supplier_detail', False)
|
|
||||||
part_detail = kwargs.pop('part_detail', False)
|
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
if isGeneratingSchema():
|
|
||||||
return
|
|
||||||
|
|
||||||
if not supplier_detail:
|
|
||||||
self.fields.pop('supplier_detail', None)
|
|
||||||
|
|
||||||
if not part_detail:
|
|
||||||
self.fields.pop('part_detail', None)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def annotate_queryset(queryset):
|
def annotate_queryset(queryset):
|
||||||
"""Prefetch related fields for the queryset."""
|
"""Prefetch related fields for the queryset."""
|
||||||
@@ -596,11 +579,15 @@ class SupplierPriceBreakSerializer(
|
|||||||
source='part.supplier', many=False, read_only=True
|
source='part.supplier', many=False, read_only=True
|
||||||
)
|
)
|
||||||
|
|
||||||
supplier_detail = CompanyBriefSerializer(
|
supplier_detail = can_filter(
|
||||||
|
CompanyBriefSerializer(
|
||||||
source='part.supplier', many=False, read_only=True, allow_null=True
|
source='part.supplier', many=False, read_only=True, allow_null=True
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Detail serializer for SupplierPart
|
# Detail serializer for SupplierPart
|
||||||
part_detail = SupplierPartSerializer(
|
part_detail = can_filter(
|
||||||
|
SupplierPartSerializer(
|
||||||
source='part', brief=True, many=False, read_only=True, allow_null=True
|
source='part', brief=True, many=False, read_only=True, allow_null=True
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user