mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Allow SupplierPart list to be filtered by SKU (#3417)
* Allow SupplierPart list to be filtered by SKU * Bump API version * Allow SupplierPart list to be filtered by MPN (manufacturer part number) * Simplify filter definition * Code formatting * Update API docs
This commit is contained in:
parent
794e375009
commit
74fbd30982
@ -2,11 +2,15 @@
|
||||
|
||||
|
||||
# InvenTree API version
|
||||
INVENTREE_API_VERSION = 67
|
||||
INVENTREE_API_VERSION = 68
|
||||
|
||||
"""
|
||||
Increment this API version number whenever there is a significant change to the API that any clients need to know about
|
||||
|
||||
v68 -> 2022-07-27 : https://github.com/inventree/InvenTree/pull/3417
|
||||
- Allows SupplierPart list to be filtered by SKU value
|
||||
- Allows SupplierPart list to be filtered by MPN value
|
||||
|
||||
v67 -> 2022-07-25 : https://github.com/inventree/InvenTree/pull/3395
|
||||
- Adds a 'requirements' endpoint for Part instance
|
||||
- Provides information on outstanding order requirements for a given part
|
||||
|
@ -254,6 +254,31 @@ class ManufacturerPartParameterDetail(RetrieveUpdateDestroyAPI):
|
||||
serializer_class = ManufacturerPartParameterSerializer
|
||||
|
||||
|
||||
class SupplierPartFilter(rest_filters.FilterSet):
|
||||
"""API filters for the SupplierPartList endpoint"""
|
||||
|
||||
class Meta:
|
||||
"""Metaclass option"""
|
||||
|
||||
model = SupplierPart
|
||||
fields = [
|
||||
'supplier',
|
||||
'part',
|
||||
'manufacturer_part',
|
||||
'SKU',
|
||||
]
|
||||
|
||||
# Filter by 'active' status of linked part
|
||||
active = rest_filters.BooleanFilter(field_name='part__active')
|
||||
|
||||
# Filter by the 'MPN' of linked manufacturer part
|
||||
MPN = rest_filters.CharFilter(
|
||||
label='Manufacturer Part Number',
|
||||
field_name='manufacturer_part__MPN',
|
||||
lookup_expr='iexact'
|
||||
)
|
||||
|
||||
|
||||
class SupplierPartList(ListCreateDestroyAPIView):
|
||||
"""API endpoint for list view of SupplierPart object.
|
||||
|
||||
@ -262,6 +287,7 @@ class SupplierPartList(ListCreateDestroyAPIView):
|
||||
"""
|
||||
|
||||
queryset = SupplierPart.objects.all()
|
||||
filterset_class = SupplierPartFilter
|
||||
|
||||
def get_queryset(self, *args, **kwargs):
|
||||
"""Return annotated queryest object for the SupplierPart list"""
|
||||
@ -282,37 +308,12 @@ class SupplierPartList(ListCreateDestroyAPIView):
|
||||
if manufacturer is not None:
|
||||
queryset = queryset.filter(manufacturer_part__manufacturer=manufacturer)
|
||||
|
||||
# Filter by supplier
|
||||
supplier = params.get('supplier', None)
|
||||
|
||||
if supplier is not None:
|
||||
queryset = queryset.filter(supplier=supplier)
|
||||
|
||||
# Filter by EITHER manufacturer or supplier
|
||||
company = params.get('company', None)
|
||||
|
||||
if company is not None:
|
||||
queryset = queryset.filter(Q(manufacturer_part__manufacturer=company) | Q(supplier=company))
|
||||
|
||||
# Filter by parent part?
|
||||
part = params.get('part', None)
|
||||
|
||||
if part is not None:
|
||||
queryset = queryset.filter(part=part)
|
||||
|
||||
# Filter by manufacturer part?
|
||||
manufacturer_part = params.get('manufacturer_part', None)
|
||||
|
||||
if manufacturer_part is not None:
|
||||
queryset = queryset.filter(manufacturer_part=manufacturer_part)
|
||||
|
||||
# Filter by 'active' status of the part?
|
||||
active = params.get('active', None)
|
||||
|
||||
if active is not None:
|
||||
active = str2bool(active)
|
||||
queryset = queryset.filter(part__active=active)
|
||||
|
||||
return queryset
|
||||
|
||||
def get_serializer(self, *args, **kwargs):
|
||||
|
Loading…
Reference in New Issue
Block a user