2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-04 20:51:00 +00:00

Improve / simplify logic for file attachments against test result object

This commit is contained in:
Oliver Walters
2020-05-23 11:30:42 +10:00
parent 50987f47b0
commit e63342418f
6 changed files with 29 additions and 60 deletions

View File

@ -292,17 +292,6 @@ 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
@ -320,8 +309,6 @@ 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