From 1cc09778168c8cc8a6ac4c5bf4f2f6f916408d0b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 17 May 2020 22:33:41 +1000 Subject: [PATCH] Display testing status for a stock item --- InvenTree/part/views.py | 1 - InvenTree/stock/models.py | 3 +++ InvenTree/stock/templates/stock/item_base.html | 13 +++++++++++++ InvenTree/stock/templates/stock/item_tests.html | 3 ++- InvenTree/stock/tests.py | 6 ------ InvenTree/templates/js/stock.html | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index c81df31484..eda1db923b 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -301,7 +301,6 @@ class MakePartVariant(AjaxCreateView): form = super(AjaxCreateView, self).get_form() # Hide some variant-related fields - form.fields['is_template'].widget = HiddenInput() form.fields['variant_of'].widget = HiddenInput() return form diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index ad2382c3e6..c50a58bea9 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -1000,6 +1000,9 @@ class StockItem(MPTTModel): 'failed': failed, } + def hasRequiredTests(self): + return self.part.getRequiredTests().count() > 0 + def passedAllRequiredTests(self): status = self.requiredTestStatus() diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 4e2d6b7439..782e51a2b8 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -15,6 +15,12 @@ InvenTree | {% trans "Stock Item" %} - {{ item }} {% block pre_content %} {% include 'stock/loc_link.html' with location=item.location %} +{% if item.hasRequiredTests and not item.passedAllRequiredTests %} +
+ {% trans "This stock item has not passed all required tests" %} +
+{% endif %} + {% for allocation in item.sales_order_allocations.all %}
{% trans "This stock item is allocated to Sales Order" %} #{{ allocation.line.order.reference }} ({% trans "Quantity" %}: {% decimal allocation.quantity %}) @@ -221,6 +227,13 @@ InvenTree | {% trans "Stock Item" %} - {{ item }} {% trans "Status" %} {% stock_status_label item.status %} + {% if item.hasRequiredTests %} + + + {% trans "Tests" %} + {{ item.requiredTestStatus.passed }} / {{ item.requiredTestStatus.total }} + + {% endif %} {% endblock %} diff --git a/InvenTree/stock/templates/stock/item_tests.html b/InvenTree/stock/templates/stock/item_tests.html index 51c0bd8ed6..6a69d55eb9 100644 --- a/InvenTree/stock/templates/stock/item_tests.html +++ b/InvenTree/stock/templates/stock/item_tests.html @@ -36,7 +36,8 @@ loadStockTestResultsTable( ); function reloadTable() { - $("#test-result-table").bootstrapTable("refresh"); + location.reload(); + //$("#test-result-table").bootstrapTable("refresh"); } $("#add-test-result").click(function() { diff --git a/InvenTree/stock/tests.py b/InvenTree/stock/tests.py index da46fee064..045cbe164e 100644 --- a/InvenTree/stock/tests.py +++ b/InvenTree/stock/tests.py @@ -456,11 +456,5 @@ class TestResultTest(StockTest): test='sew cushion', result=True ) - - results = item.testResultMap() - - for key in results.keys(): - result = results[key] self.assertTrue(item.passedAllRequiredTests()) - diff --git a/InvenTree/templates/js/stock.html b/InvenTree/templates/js/stock.html index f0bcd47a3e..49c3151ff0 100644 --- a/InvenTree/templates/js/stock.html +++ b/InvenTree/templates/js/stock.html @@ -68,7 +68,7 @@ function loadStockTestResultsTable(table, options) { html += makeIconButton('fa-plus icon-green', 'button-test-add', row.test_name, '{% trans "Add test result" %}'); - if (!grouped) { + if (!grouped && row.result != null) { var pk = row.pk; html += makeIconButton('fa-edit icon-blue', 'button-test-edit', pk, '{% trans "Edit test result" %}'); html += makeIconButton('fa-trash-alt icon-red', 'button-test-delete', pk, '{% trans "Delete test result" %}');