@@ -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
-
-
-
- SKU |
- Supplier |
- MPN |
- URL |
-
-
-
-{% for spart in part.supplier_parts.all %}
-
- {{ spart.SKU }} |
- {{ spart.supplier.name }} |
- {{ spart.manufacturer_string }} |
-
- {% if spart.URL %}
- {{ spart.URL }}
- {% endif %}
- |
-
-{% endfor %}
-
+{% if part.supplier_count > 0 %}
+{{ part.name }} is available from {{ part.supplier_count }} suppliers.
+
+
+{% 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