From b8f5c8cca74a5e890ff18f1d5e0e60d2d70e39c4 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 16 May 2019 22:12:13 +1000 Subject: [PATCH 1/5] Add confirmation box to stocktake form --- InvenTree/static/script/inventree/stock.js | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/InvenTree/static/script/inventree/stock.js b/InvenTree/static/script/inventree/stock.js index 9f9c5fd40b..8824965c41 100644 --- a/InvenTree/static/script/inventree/stock.js +++ b/InvenTree/static/script/inventree/stock.js @@ -87,8 +87,18 @@ function updateStock(items, options={}) { html += ''; html += "
"; + html += "

Note field must be filled

"; + + html += ` +
+
+ +

Confirm stock count

+
`; - html += "

Note field must be filled

"; var title = ''; @@ -109,6 +119,7 @@ function updateStock(items, options={}) { }); $(modal).find('#note-warning').hide(); + $(modal).find('#confirm-warning').hide(); modalEnable(modal, true); @@ -116,13 +127,23 @@ function updateStock(items, options={}) { var stocktake = []; var notes = $(modal).find('#stocktake-notes').val(); + var confirm = $(modal).find('#stocktake-confirm').is(':checked'); + + var valid = true; if (!notes) { $(modal).find('#note-warning').show(); - return false; + valid = false; } - var valid = true; + if (!confirm) { + $(modal).find('#confirm-warning').show(); + valid = false; + } + + if (!valid) { + return false; + } // Form stocktake data for (idx = 0; idx < items.length; idx++) { From 0a1887477ca7aace22f64311db8394959b3c86bf Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 16 May 2019 22:15:44 +1000 Subject: [PATCH 2/5] Create template for stock table --- .../templates/company/detail_stock.html | 17 ++++++------- InvenTree/part/templates/part/stock.html | 24 +++---------------- InvenTree/stock/templates/stock/location.html | 19 +-------------- InvenTree/templates/stock_table.html | 17 +++++++++++++ 4 files changed, 30 insertions(+), 47 deletions(-) create mode 100644 InvenTree/templates/stock_table.html diff --git a/InvenTree/company/templates/company/detail_stock.html b/InvenTree/company/templates/company/detail_stock.html index 89ea0fdb2f..5bc7b9598a 100644 --- a/InvenTree/company/templates/company/detail_stock.html +++ b/InvenTree/company/templates/company/detail_stock.html @@ -7,19 +7,20 @@

Supplier Stock

- -
+{% include "stock_table.html" %} {% endblock %} {% block js_ready %} {{ block.super }} - loadStockTable($('#stock-table'), - { - url: "{% url 'api-stock-list' %}", - params: { - supplier: {{ company.id }}, - } + loadStockTable($('#stock-table'), { + url: "{% url 'api-stock-list' %}", + params: { + supplier: {{ company.id }}, + }, + buttons: [ + '#stock-options', + ] }); {% endblock %} \ No newline at end of file diff --git a/InvenTree/part/templates/part/stock.html b/InvenTree/part/templates/part/stock.html index 3311dafb8d..60f283bea9 100644 --- a/InvenTree/part/templates/part/stock.html +++ b/InvenTree/part/templates/part/stock.html @@ -13,25 +13,7 @@
-
- {% if part.active %} - - {% endif %} - -
- - -
- +{% include "stock_table.html" %} {% endblock %} @@ -87,14 +69,14 @@ return false; }); - $("#multi-item-take").click(function() { + $("#multi-item-remove").click(function() { updateStockItems({ action: 'remove', }); return false; }); - $("#multi-item-give").click(function() { + $("#multi-item-add").click(function() { updateStockItems({ action: 'add', }); diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 9ea210a04e..311f0773cd 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -44,24 +44,7 @@
-
-
- - -
-
- - -
- +{% include "stock_table.html" %} {% include 'modals.html' %} diff --git a/InvenTree/templates/stock_table.html b/InvenTree/templates/stock_table.html new file mode 100644 index 0000000000..f5411fabb8 --- /dev/null +++ b/InvenTree/templates/stock_table.html @@ -0,0 +1,17 @@ +
+
+ + +
+
+ + +
\ No newline at end of file From 117fd701cded3ab728dbc66a81f1bba5fbb8b38d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 16 May 2019 22:19:49 +1000 Subject: [PATCH 3/5] Refactor some code --- InvenTree/part/templates/part/stock.html | 39 ------------------ InvenTree/static/script/inventree/stock.js | 36 ++++++++++++++++ InvenTree/stock/templates/stock/location.html | 41 +------------------ 3 files changed, 37 insertions(+), 79 deletions(-) diff --git a/InvenTree/part/templates/part/stock.html b/InvenTree/part/templates/part/stock.html index 60f283bea9..8b9561ea2e 100644 --- a/InvenTree/part/templates/part/stock.html +++ b/InvenTree/part/templates/part/stock.html @@ -44,43 +44,4 @@ url: "{% url 'api-stock-list' %}", }); - function selectedStock() { - return $("#stock-table").bootstrapTable('getSelections'); - } - - $("#multi-item-move").click(function() { - - var items = selectedStock(); - - moveStockItems(items, - { - success: function() { - $("#stock-table").bootstrapTable('refresh'); - } - }); - - return false; - }); - - $("#multi-item-stocktake").click(function() { - updateStockItems({ - action: 'stocktake' - }); - return false; - }); - - $("#multi-item-remove").click(function() { - updateStockItems({ - action: 'remove', - }); - return false; - }); - - $("#multi-item-add").click(function() { - updateStockItems({ - action: 'add', - }); - return false; - }) - {% endblock %} \ No newline at end of file diff --git a/InvenTree/static/script/inventree/stock.js b/InvenTree/static/script/inventree/stock.js index 8824965c41..b8d674556b 100644 --- a/InvenTree/static/script/inventree/stock.js +++ b/InvenTree/static/script/inventree/stock.js @@ -434,6 +434,42 @@ function loadStockTable(table, options) { if (options.buttons) { linkButtonsToSelection(table, options.buttons); } + + // Automatically link button callbacks + $('#multi-item-stocktake').click(function() { + updateStockItems({ + action: 'stocktake', + }); + return false; + }); + + $('#multi-item-remove').click(function() { + updateStockItems({ + action: 'remove', + }); + return false; + }); + + $('#multi-item-add').click(function() { + updateStockItems({ + action: 'add', + }); + return false; + }); + + $("#multi-item-move").click(function() { + + var items = $("#stock-table").bootstrapTable('getSelections'); + + moveStockItems(items, + { + success: function() { + $("#stock-table").bootstrapTable('refresh'); + } + }); + + return false; + }); } diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 311f0773cd..ae36078ece 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -132,46 +132,7 @@ return false; }); - - function selectedStock() { - return $("#stock-table").bootstrapTable('getSelections'); - } - - $("#multi-item-move").click(function() { - - var items = selectedStock(); - - moveStockItems(items, - { - success: function() { - $("#stock-table").bootstrapTable('refresh'); - } - }); - - return false; - }); - - $('#multi-item-stocktake').click(function() { - updateStockItems({ - action: 'stocktake', - }); - return false; - }); - - $('#multi-item-remove').click(function() { - updateStockItems({ - action: 'remove', - }); - return false; - }); - - $('#multi-item-add').click(function() { - updateStockItems({ - action: 'add', - }); - return false; - }); - + loadStockTable($("#stock-table"), { buttons: [ '#stock-options', From 5ebc7b040a119385e9fa4963f3e9c9037bf252dd Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 16 May 2019 22:23:31 +1000 Subject: [PATCH 4/5] Show current quantity in stocktake form --- InvenTree/static/script/inventree/stock.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/InvenTree/static/script/inventree/stock.js b/InvenTree/static/script/inventree/stock.js index b8d674556b..d34ed9beee 100644 --- a/InvenTree/static/script/inventree/stock.js +++ b/InvenTree/static/script/inventree/stock.js @@ -43,6 +43,7 @@ function updateStock(items, options={}) { html += 'Item'; html += 'Location'; html += 'Quantity'; + html += '' + options.action + ''; html += ''; @@ -71,6 +72,9 @@ function updateStock(items, options={}) { } else { html += 'No location set'; } + + html += '' + item.quantity + ''; + html += " Date: Thu, 16 May 2019 22:29:39 +1000 Subject: [PATCH 5/5] Display number of supplier parts in supplier list --- InvenTree/company/serializers.py | 20 ++++++++++++++++++- .../company/templates/company/index.html | 9 ++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/InvenTree/company/serializers.py b/InvenTree/company/serializers.py index 88792f7f64..2967dbebd5 100644 --- a/InvenTree/company/serializers.py +++ b/InvenTree/company/serializers.py @@ -25,7 +25,25 @@ class CompanySerializer(serializers.ModelSerializer): """ Serializer for Company object (full detail) """ url = serializers.CharField(source='get_absolute_url', read_only=True) + part_count = serializers.CharField(read_only=True) class Meta: model = Company - fields = '__all__' + fields = [ + 'id', + 'url', + 'name', + 'description', + 'website', + 'name', + 'phone', + 'address', + 'email', + 'contact', + 'URL', + 'image', + 'notes', + 'is_customer', + 'is_supplier', + 'part_count' + ] diff --git a/InvenTree/company/templates/company/index.html b/InvenTree/company/templates/company/index.html index d4a8659798..cea452fdc1 100644 --- a/InvenTree/company/templates/company/index.html +++ b/InvenTree/company/templates/company/index.html @@ -73,7 +73,14 @@ InvenTree | Supplier List } return ''; } - } + }, + { + field: 'part_count', + title: 'Parts', + formatter: function(value, row, index, field) { + return renderLink(value, row.url + 'parts/'); + } + }, ], url: "{% url 'api-company-list' %}" });