From ef032d406f78149008f3e4a789d19a06560873fe Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 15 Dec 2020 11:57:52 +1100 Subject: [PATCH 1/2] Bugfix for stock report filter --- InvenTree/report/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index 7b7f01f7a1..b3725cadc0 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -193,6 +193,9 @@ class TestReport(ReportTemplateBase): items = StockItem.objects.filter(**filters) + # Ensure the provided StockItem object matches the filters + items = items.filter(pk=item.pk) + return items.exists() def get_context_data(self, request): From 297bfd776c0e3d7a056d5ced4d07f594df9da271 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 15 Dec 2020 12:31:02 +1100 Subject: [PATCH 2/2] Pre-select a template if only one matching one exists --- InvenTree/stock/views.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 18c05f100b..3a29b66ee3 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -510,7 +510,22 @@ class StockItemTestReportSelect(AjaxView): def get_form(self): stock_item = StockItem.objects.get(pk=self.kwargs['pk']) - return StockForms.TestReportFormatForm(stock_item) + form = StockForms.TestReportFormatForm(stock_item) + + return form + + def get_initial(self): + + initials = super().get_initial() + + form = self.get_form() + options = form.fields['template'].queryset + + # If only a single template is available, pre-select it + if options.count() == 1: + initials['template'] = options[0] + + return initials def post(self, request, *args, **kwargs):