From 7c892263f8e8708f9e4383d6fd19858759e0e338 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 13 Apr 2020 19:33:44 +1000 Subject: [PATCH] More API fixes - Allow searching supplier parts by manufacturer name - Better rendering of supplier part table (cherry picked from commit 62199aedf5089bd449af339d5266f8875baf4d29) --- .../static/script/inventree/company.js | 21 +++++++++- .../static/script/inventree/stock.js | 8 +++- InvenTree/company/api.py | 2 +- InvenTree/templates/InvenTree/search.html | 42 ++++++------------- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/InvenTree/InvenTree/static/script/inventree/company.js b/InvenTree/InvenTree/static/script/inventree/company.js index 64022b2989..86974630ef 100644 --- a/InvenTree/InvenTree/static/script/inventree/company.js +++ b/InvenTree/InvenTree/static/script/inventree/company.js @@ -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 { diff --git a/InvenTree/InvenTree/static/script/inventree/stock.js b/InvenTree/InvenTree/static/script/inventree/stock.js index e99e559ed9..bf0ddbef5e 100644 --- a/InvenTree/InvenTree/static/script/inventree/stock.js +++ b/InvenTree/InvenTree/static/script/inventree/stock.js @@ -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); } diff --git a/InvenTree/company/api.py b/InvenTree/company/api.py index fcc724e5fd..db92baafad 100644 --- a/InvenTree/company/api.py +++ b/InvenTree/company/api.py @@ -130,7 +130,7 @@ class SupplierPartList(generics.ListCreateAPIView): search_fields = [ 'SKU', 'supplier__name', - 'manufacturer_name', + 'manufacturer__name', 'description', 'MPN', ] diff --git a/InvenTree/templates/InvenTree/search.html b/InvenTree/templates/InvenTree/search.html index e13291a76a..e8cda96809 100644 --- a/InvenTree/templates/InvenTree/search.html +++ b/InvenTree/templates/InvenTree/search.html @@ -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 %} \ No newline at end of file