diff --git a/InvenTree/company/serializers.py b/InvenTree/company/serializers.py index bb99f18e75..db3aebf4fa 100644 --- a/InvenTree/company/serializers.py +++ b/InvenTree/company/serializers.py @@ -3,7 +3,19 @@ from rest_framework import serializers from .models import Company -class CompanySerializer(serializers.HyperlinkedModelSerializer): +class CompanyBriefSerializer(serializers.ModelSerializer): + + url = serializers.CharField(source='get_absolute_url', read_only=True) + + class Meta: + model = Company + fields = [ + 'pk', + 'url', + 'name' + ] + +class CompanySerializer(serializers.ModelSerializer): url = serializers.CharField(source='get_absolute_url', read_only=True) diff --git a/InvenTree/company/templates/company/detail_part.html b/InvenTree/company/templates/company/detail_part.html index a37dfb6dbd..71ebd41386 100644 --- a/InvenTree/company/templates/company/detail_part.html +++ b/InvenTree/company/templates/company/detail_part.html @@ -6,29 +6,7 @@

Company Parts

- - - - - - - - - - -{% for part in company.parts.all %} - - - - - - -{% endfor %} - +
SKUPartMPNURL
{{ part.SKU }} - {% if part.part %} - {{ part.part.name }} - {% endif %} - {{ part.manufacturer_string }}{{ part.URL }}
@@ -43,7 +21,7 @@ {% endblock %} {% block js_ready %} - + $("#part-create").click(function () { launchModalForm("#modal-form", "{% url 'supplier-part-create' %}", @@ -54,4 +32,39 @@ reload: true, }); }); + + $("#part-table").bootstrapTable({ + sortable: true, + search: true, + queryParams: function(p) { + return { + supplier: {{ company.id }} + } + }, + columns: [ + { + sortable: true, + field: 'part', + title: 'Part', + formatter: function(value, row, index, field) { + return renderLink(value.name, value.url); + } + }, + { + sortable: true, + field: 'SKU', + title: 'SKU', + formatter: function(value, row, index, field) { + return renderLink(value, row.url); + } + }, + { + sortable: true, + field: 'manufacturer', + title: 'Manufacturer', + } + ], + url: "{% url 'api-part-supplier-list' %}" + }); + {% endblock %} \ No newline at end of file diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 1083caf3a6..0510df69d2 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -8,7 +8,10 @@ from rest_framework import generics, permissions from django.conf.urls import url from .models import Part, PartCategory, BomItem +from .models import SupplierPart + from .serializers import PartSerializer, BomItemSerializer +from .serializers import SupplierPartSerializer from InvenTree.views import TreeSerializer @@ -70,10 +73,32 @@ class BomList(generics.ListAPIView): ] +class SupplierPartList(generics.ListAPIView): + + queryset = SupplierPart.objects.all() + serializer_class = SupplierPartSerializer + + permission_classes = [ + permissions.IsAuthenticatedOrReadOnly, + ] + + filter_backends = [ + DjangoFilterBackend, + filters.SearchFilter, + filters.OrderingFilter, + ] + + filter_fields = [ + 'part', + 'supplier' + ] + + part_api_urls = [ url(r'^tree/?', PartCategoryTree.as_view(), name='api-part-tree'), + url(r'^supplier/?', SupplierPartList.as_view(), name='api-part-supplier-list'), url(r'^bom/?', BomList.as_view(), name='api-bom-list'), url(r'^.*$', PartList.as_view(), name='api-part-list'), ] diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 5812c40d99..c942d0a212 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -1,7 +1,9 @@ from rest_framework import serializers from .models import Part, PartCategory, BomItem +from .models import SupplierPart +from company.serializers import CompanyBriefSerializer class CategoryBriefSerializer(serializers.ModelSerializer): @@ -75,4 +77,24 @@ class BomItemSerializer(serializers.ModelSerializer): 'part', 'sub_part', 'quantity' + ] + + +class SupplierPartSerializer(serializers.ModelSerializer): + + url = serializers.CharField(source='get_absolute_url', read_only=True) + + part = PartBriefSerializer(many=False, read_only=True) + supplier = CompanyBriefSerializer(many=False, read_only=True) + + class Meta: + model = SupplierPart + fields = [ + 'pk', + 'url', + 'part', + 'supplier', + 'SKU', + 'manufacturer', + 'MPN', ] \ No newline at end of file diff --git a/InvenTree/part/templates/part/supplier.html b/InvenTree/part/templates/part/supplier.html index fc7bd6458d..47035a2972 100644 --- a/InvenTree/part/templates/part/supplier.html +++ b/InvenTree/part/templates/part/supplier.html @@ -6,30 +6,14 @@

Part Suppliers

- - - - - - - - - - -{% for spart in part.supplier_parts.all %} - - - - - - -{% endfor %} - +{% if part.supplier_count > 0 %} +

{{ part.name }} is available from {{ part.supplier_count }} suppliers.

+ +
SKUSupplierMPNURL
{{ spart.SKU }}{{ spart.supplier.name }}{{ spart.manufacturer_string }} - {% if spart.URL %} - {{ spart.URL }} - {% endif %} -
+{% else %} +

{{ part.name }} is not available from any suppliers.

+{% endif %}
@@ -51,4 +35,39 @@ data: {part: {{ part.id }} } }); }); + + $("#supplier-table").bootstrapTable({ + sortable: true, + search: true, + queryParams: function(p) { + return { + part: {{ part.id }} + } + }, + columns: [ + { + sortable: true, + field: 'supplier', + title: 'Supplier', + formatter: function(value, row, index, field) { + return renderLink(value.name, value.url); + } + }, + { + sortable: true, + field: 'SKU', + title: 'SKU', + formatter: function(value, row, index, field) { + return renderLink(value, row.url); + } + }, + { + sortable: true, + field: 'manufacturer', + title: 'Manufacturer', + } + ], + url: "{% url 'api-part-supplier-list' %}" + }); + {% endblock %} \ No newline at end of file