2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Add ability to edit / assign attatched files to test result data

This commit is contained in:
Oliver Walters
2020-05-17 16:17:05 +10:00
parent e9ed50fc4b
commit cd0e66e3c6
3 changed files with 17 additions and 0 deletions

View File

@ -46,6 +46,7 @@ class EditStockItemTestResultForm(HelperForm):
'test',
'result',
'value',
'attachment',
'notes',
]

View File

@ -261,6 +261,17 @@ class StockItemTestResultCreate(AjaxCreateView):
form = super().get_form()
form.fields['stock_item'].widget = HiddenInput()
# Extract the StockItem object
item_id = form['stock_item'].value()
# Limit the options for the file attachments
try:
stock_item = StockItem.objects.get(pk=item_id)
form.fields['attachment'].queryset = stock_item.attachments.all()
except (ValueError, StockItem.DoesNotExist):
# Hide the attachments field
form.fields['attachment'].widget = HiddenInput()
return form
@ -278,6 +289,8 @@ class StockItemTestResultEdit(AjaxUpdateView):
form = super().get_form()
form.fields['stock_item'].widget = HiddenInput()
form.fields['attachment'].queryset = self.object.stock_item.attachments.all()
return form