mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
More API / JSON stuff
- SupplierPart JSON API - Part supplier list - Company part list
This commit is contained in:
parent
49287c0c61
commit
f995f54390
@ -3,7 +3,19 @@ from rest_framework import serializers
|
|||||||
from .models import Company
|
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)
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||||
|
|
||||||
|
@ -6,29 +6,7 @@
|
|||||||
|
|
||||||
<h3>Company Parts</h3>
|
<h3>Company Parts</h3>
|
||||||
|
|
||||||
<table class='table table-striped' id='part-list' data-sorting='true' data-filtering='true'>
|
<table clas='table table-striped table-condensed' id='part-table'>
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>SKU</th>
|
|
||||||
<th>Part</th>
|
|
||||||
<th>MPN</th>
|
|
||||||
<th>URL</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for part in company.parts.all %}
|
|
||||||
<tr>
|
|
||||||
<td><a href="{% url 'supplier-part-detail' part.id %}">{{ part.SKU }}</a></td>
|
|
||||||
<td>
|
|
||||||
{% if part.part %}
|
|
||||||
<a href="{% url 'part-suppliers' part.part.id %}">{{ part.part.name }}</a>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
<td>{{ part.manufacturer_string }}</td>
|
|
||||||
<td>{{ part.URL }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class='container-fluid'>
|
<div class='container-fluid'>
|
||||||
@ -43,7 +21,7 @@
|
|||||||
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
|
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block js_ready %}
|
{% block js_ready %}
|
||||||
|
|
||||||
$("#part-create").click(function () {
|
$("#part-create").click(function () {
|
||||||
launchModalForm("#modal-form",
|
launchModalForm("#modal-form",
|
||||||
"{% url 'supplier-part-create' %}",
|
"{% url 'supplier-part-create' %}",
|
||||||
@ -54,4 +32,39 @@
|
|||||||
reload: true,
|
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 %}
|
{% endblock %}
|
@ -8,7 +8,10 @@ from rest_framework import generics, permissions
|
|||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from .models import Part, PartCategory, BomItem
|
from .models import Part, PartCategory, BomItem
|
||||||
|
from .models import SupplierPart
|
||||||
|
|
||||||
from .serializers import PartSerializer, BomItemSerializer
|
from .serializers import PartSerializer, BomItemSerializer
|
||||||
|
from .serializers import SupplierPartSerializer
|
||||||
|
|
||||||
from InvenTree.views import TreeSerializer
|
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 = [
|
part_api_urls = [
|
||||||
|
|
||||||
url(r'^tree/?', PartCategoryTree.as_view(), name='api-part-tree'),
|
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'^bom/?', BomList.as_view(), name='api-bom-list'),
|
||||||
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
||||||
]
|
]
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from .models import Part, PartCategory, BomItem
|
from .models import Part, PartCategory, BomItem
|
||||||
|
from .models import SupplierPart
|
||||||
|
|
||||||
|
from company.serializers import CompanyBriefSerializer
|
||||||
|
|
||||||
class CategoryBriefSerializer(serializers.ModelSerializer):
|
class CategoryBriefSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
@ -75,4 +77,24 @@ class BomItemSerializer(serializers.ModelSerializer):
|
|||||||
'part',
|
'part',
|
||||||
'sub_part',
|
'sub_part',
|
||||||
'quantity'
|
'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',
|
||||||
]
|
]
|
@ -6,30 +6,14 @@
|
|||||||
|
|
||||||
<h3>Part Suppliers</h3>
|
<h3>Part Suppliers</h3>
|
||||||
|
|
||||||
<table class="table table-striped" id='supplier-table' data-sorting='true'>
|
{% if part.supplier_count > 0 %}
|
||||||
<thead>
|
<p><b>{{ part.name }}</b> is available from {{ part.supplier_count }} suppliers.</p>
|
||||||
<tr>
|
|
||||||
<th>SKU</th>
|
<table class="table table-striped table-condensed" id='supplier-table'>
|
||||||
<th>Supplier</th>
|
|
||||||
<th>MPN</th>
|
|
||||||
<th>URL</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for spart in part.supplier_parts.all %}
|
|
||||||
<tr>
|
|
||||||
<td><a href="{% url 'supplier-part-detail' spart.id %}">{{ spart.SKU }}</a></td>
|
|
||||||
<td><a href="{% url 'company-detail' spart.supplier.id %}">{{ spart.supplier.name }}</a></td>
|
|
||||||
<td>{{ spart.manufacturer_string }}</td>
|
|
||||||
<td>
|
|
||||||
{% if spart.URL %}
|
|
||||||
<a href="{{ spart.URL }}">{{ spart.URL }}</a>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<p><b>{{ part.name }}</b> is not available from any suppliers.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class='container-fluid'>
|
<div class='container-fluid'>
|
||||||
<button class="btn btn-success" id='supplier-create'>New Supplier Part</button>
|
<button class="btn btn-success" id='supplier-create'>New Supplier Part</button>
|
||||||
@ -51,4 +35,39 @@
|
|||||||
data: {part: {{ part.id }} }
|
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 %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user