mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improve BOM API endpoint
- Origin at /api/bom - Add detail view - Add create power to list view
This commit is contained in:
parent
4e3b8bdd92
commit
da540e1b26
@ -11,7 +11,7 @@ from stock.urls import stock_urls
|
|||||||
|
|
||||||
from build.urls import build_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 company.api import company_api_urls
|
||||||
from stock.api import stock_api_urls
|
from stock.api import stock_api_urls
|
||||||
from build.api import build_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"
|
admin.site.site_header = "InvenTree Admin"
|
||||||
|
|
||||||
apipatterns = [
|
apipatterns = [
|
||||||
url(r'^part/', include(part_api_urls)),
|
url(r'^part/?', include(part_api_urls)),
|
||||||
url(r'^company/', include(company_api_urls)),
|
url(r'^bom/?', include(bom_api_urls)),
|
||||||
url(r'^stock/', include(stock_api_urls)),
|
url(r'^company/?', include(company_api_urls)),
|
||||||
url(r'^build/', include(build_api_urls)),
|
url(r'^stock/?', include(stock_api_urls)),
|
||||||
|
url(r'^build/?', include(build_api_urls)),
|
||||||
|
|
||||||
# User URLs
|
# User URLs
|
||||||
url(r'^user/', include(user_urls)),
|
url(r'^user/', include(user_urls)),
|
||||||
|
@ -124,7 +124,7 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class BomList(generics.ListAPIView):
|
class BomList(generics.ListCreateAPIView):
|
||||||
|
|
||||||
queryset = BomItem.objects.all()
|
queryset = BomItem.objects.all()
|
||||||
serializer_class = BomItemSerializer
|
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):
|
class SupplierPartList(generics.ListCreateAPIView):
|
||||||
|
|
||||||
queryset = SupplierPart.objects.all()
|
queryset = SupplierPart.objects.all()
|
||||||
@ -213,9 +223,16 @@ part_api_urls = [
|
|||||||
url(r'^supplier/?', include(supplier_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'^price-break/?', SupplierPriceBreakList.as_view(), name='api-part-supplier-price'),
|
||||||
url(r'^bom/?', BomList.as_view(), name='api-bom-list'),
|
|
||||||
|
|
||||||
url(r'^(?P<pk>\d+)/', PartDetail.as_view(), name='api-part-detail'),
|
url(r'^(?P<pk>\d+)/', PartDetail.as_view(), name='api-part-detail'),
|
||||||
|
|
||||||
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
bom_api_urls = [
|
||||||
|
# BOM Item Detail
|
||||||
|
url('^(?P<pk>\d+)/?', BomDetail.as_view(), name='api-bom-detail'),
|
||||||
|
|
||||||
|
# Catch-all
|
||||||
|
url(r'^.*$', BomList.as_view(), name='api-bom-list'),
|
||||||
|
]
|
@ -67,18 +67,20 @@ class PartSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class BomItemSerializer(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)
|
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
||||||
sub_part = PartBriefSerializer(many=False, read_only=True)
|
sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = BomItem
|
model = BomItem
|
||||||
fields = [
|
fields = [
|
||||||
'pk',
|
'pk',
|
||||||
'url',
|
# 'url',
|
||||||
'part',
|
'part',
|
||||||
|
'part_detail',
|
||||||
'sub_part',
|
'sub_part',
|
||||||
|
'sub_part_detail',
|
||||||
'quantity',
|
'quantity',
|
||||||
'note',
|
'note',
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user