From 71681bfda1c3ab8e2c3549c8c26f4197c88eff87 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 22 May 2020 21:38:05 +1000 Subject: [PATCH] Add a button if a stock item test report is available --- InvenTree/part/models.py | 5 +++++ InvenTree/report/models.py | 1 + InvenTree/stock/templates/stock/item_base.html | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 31a35d8cd3..735a6de574 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -372,6 +372,11 @@ class Part(MPTTModel): return templates + def has_test_report_templates(self): + """ Return True if this part has a TestReport defined """ + + return len(self.get_test_report_templates()) > 0 + def get_absolute_url(self): """ Return the web URL for viewing this part """ return reverse('part-detail', kwargs={'pk': self.id}) diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index 60580b900d..9cf7778641 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -212,6 +212,7 @@ class TestReport(ReportTemplateBase, PartFilterMixin): def getSubdir(self): return 'test' + # Requires a stock_item object to be given to it before rendering stock_item = None def get_context_data(self, request): diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 782e51a2b8..b01442f3b5 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -93,8 +93,13 @@ InvenTree | {% trans "Stock Item" %} - {{ item }} {% endif %} + {% if item.part.has_test_report_templates %} + + {% endif %} {% if item.can_delete %}