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
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
@ -6,29 +6,7 @@
|
||||
|
||||
<h3>Company Parts</h3>
|
||||
|
||||
<table class='table table-striped' id='part-list' data-sorting='true' data-filtering='true'>
|
||||
<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 clas='table table-striped table-condensed' id='part-table'>
|
||||
</table>
|
||||
|
||||
<div class='container-fluid'>
|
||||
@ -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 %}
|
@ -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'),
|
||||
]
|
||||
|
@ -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):
|
||||
|
||||
@ -76,3 +78,23 @@ class BomItemSerializer(serializers.ModelSerializer):
|
||||
'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',
|
||||
]
|
@ -6,30 +6,14 @@
|
||||
|
||||
<h3>Part Suppliers</h3>
|
||||
|
||||
<table class="table table-striped" id='supplier-table' data-sorting='true'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>SKU</th>
|
||||
<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>
|
||||
{% if part.supplier_count > 0 %}
|
||||
<p><b>{{ part.name }}</b> is available from {{ part.supplier_count }} suppliers.</p>
|
||||
|
||||
<table class="table table-striped table-condensed" id='supplier-table'>
|
||||
</table>
|
||||
{% else %}
|
||||
<p><b>{{ part.name }}</b> is not available from any suppliers.</p>
|
||||
{% endif %}
|
||||
|
||||
<div class='container-fluid'>
|
||||
<button class="btn btn-success" id='supplier-create'>New Supplier Part</button>
|
||||
@ -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 %}
|
Loading…
Reference in New Issue
Block a user