More API fixes

- Allow searching supplier parts by manufacturer name
- Better rendering of supplier part table
This commit is contained in:
Oliver Walters 2020-04-13 19:33:44 +10:00
parent a50ecb24c1
commit 62199aedf5
4 changed files with 39 additions and 34 deletions

View File

@ -127,6 +127,22 @@ function loadSupplierPartTable(table, url, options) {
return html;
}
},
{
sortable: true,
field: 'supplier',
title: "Supplier",
formatter: function(value, row, index, field) {
if (value) {
var name = row.supplier_detail.name;
var url = `/company/${value}/`;
var html = imageHoverIcon(row.supplier_detail.image) + renderLink(name, url);
return html;
} else {
return "-";
}
},
},
{
sortable: true,
field: 'SKU',
@ -138,11 +154,12 @@ function loadSupplierPartTable(table, url, options) {
{
sortable: true,
field: 'manufacturer',
title: '"Manufacturer"',
title: 'Manufacturer',
formatter: function(value, row, index, field) {
if (value) {
var name = row.manufacturer_detail.name;
var html = imageHoverIcon(row.manufacturer_detail.image) + renderLink(name, '/company/' + value + '/');
var url = `/company/${value}/`;
var html = imageHoverIcon(row.manufacturer_detail.image) + renderLink(name, url);
return html;
} else {

View File

@ -229,7 +229,13 @@ function loadStockTable(table, options) {
name += row.part__revision;
}
var url = `/supplier-part/${row.supplier_part}/`;
var url = '';
if (row.supplier_part) {
url = `/supplier-part/${row.supplier_part}/`;
} else {
url = `/part/${row.part}/`;
}
return imageHoverIcon(row.part__thumbnail) + renderLink(name, url);
}

View File

@ -130,7 +130,7 @@ class SupplierPartList(generics.ListCreateAPIView):
search_fields = [
'SKU',
'supplier__name',
'manufacturer_name',
'manufacturer__name',
'description',
'MPN',
]

View File

@ -140,36 +140,18 @@ InvenTree | {% trans "Search Results" %}
serach: "{{ query }}",
}
});
$("#supplier-part-results-table").inventreeTable({
url: "{% url 'api-part-supplier-list' %}",
queryParams: {
search: "{{ query }}",
},
columns: [
{
field: 'supplier_name',
title: 'Supplier',
formatter: function(value, row, index, field) {
return imageHoverIcon(row.supplier_logo) + renderLink(value, '/company/' + row.supplier + '/');
}
loadSupplierPartTable(
"#supplier-part-results-table",
"{% url 'api-supplier-part-list' %}",
{
params: {
search: "{{ query }}",
part_detail: true,
supplier_detail: true,
manufacturer_detail: true
},
{
field: 'SKU',
title: 'SKU',
formatter: function(value, row, index, field) {
return renderLink(value, row.url);
}
},
{
field: 'manufacturer',
title: 'Manufacturer',
},
{
field: 'MPN',
title: 'MPN',
}
]
});
}
);
{% endblock %}