Merge pull request #1164 from SchrodingersGat/stock-report-filter

Stock report filter
This commit is contained in:
Oliver 2020-12-15 13:32:13 +11:00 committed by GitHub
commit a7d825158c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -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):

View File

@ -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):