diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index b5a0f328da..f9a40af893 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -11,7 +11,7 @@ from stock.urls import stock_urls from build.urls import build_urls -from part.api import part_api_urls +from part.api import part_api_urls, bom_api_urls from company.api import company_api_urls from stock.api import stock_api_urls from build.api import build_api_urls @@ -29,10 +29,11 @@ from users.urls import user_urls admin.site.site_header = "InvenTree Admin" apipatterns = [ - url(r'^part/', include(part_api_urls)), - url(r'^company/', include(company_api_urls)), - url(r'^stock/', include(stock_api_urls)), - url(r'^build/', include(build_api_urls)), + url(r'^part/?', include(part_api_urls)), + url(r'^bom/?', include(bom_api_urls)), + url(r'^company/?', include(company_api_urls)), + url(r'^stock/?', include(stock_api_urls)), + url(r'^build/?', include(build_api_urls)), # User URLs url(r'^user/', include(user_urls)), diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index d3d8677428..2b4ceb69f5 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -124,7 +124,7 @@ class PartList(generics.ListCreateAPIView): ] -class BomList(generics.ListAPIView): +class BomList(generics.ListCreateAPIView): queryset = BomItem.objects.all() serializer_class = BomItemSerializer @@ -145,6 +145,16 @@ class BomList(generics.ListAPIView): ] +class BomDetail(generics.RetrieveUpdateDestroyAPIView): + + queryset = BomItem.objects.all() + serializer_class = BomItemSerializer + + permission_classes = [ + permissions.IsAuthenticatedOrReadOnly, + ] + + class SupplierPartList(generics.ListCreateAPIView): queryset = SupplierPart.objects.all() @@ -213,9 +223,16 @@ part_api_urls = [ url(r'^supplier/?', include(supplier_part_api_urls)), url(r'^price-break/?', SupplierPriceBreakList.as_view(), name='api-part-supplier-price'), - url(r'^bom/?', BomList.as_view(), name='api-bom-list'), url(r'^(?P\d+)/', PartDetail.as_view(), name='api-part-detail'), url(r'^.*$', PartList.as_view(), name='api-part-list'), ] + +bom_api_urls = [ + # BOM Item Detail + url('^(?P\d+)/?', BomDetail.as_view(), name='api-bom-detail'), + + # Catch-all + url(r'^.*$', BomList.as_view(), name='api-bom-list'), +] \ No newline at end of file diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index afafa43b17..102da8bd76 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -67,18 +67,20 @@ class PartSerializer(serializers.ModelSerializer): class BomItemSerializer(serializers.ModelSerializer): - url = serializers.CharField(source='get_absolute_url', read_only=True) + # url = serializers.CharField(source='get_absolute_url', read_only=True) - part = PartBriefSerializer(many=False, read_only=True) - sub_part = PartBriefSerializer(many=False, read_only=True) + part_detail = PartBriefSerializer(source='part', many=False, read_only=True) + sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True) class Meta: model = BomItem fields = [ 'pk', - 'url', + # 'url', 'part', + 'part_detail', 'sub_part', + 'sub_part_detail', 'quantity', 'note', ]