mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +00:00
Add ability to edit / assign attatched files to test result data
This commit is contained in:
parent
e9ed50fc4b
commit
cd0e66e3c6
@ -53,6 +53,9 @@ class InvenTreeAttachment(models.Model):
|
|||||||
|
|
||||||
return "attachments"
|
return "attachments"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return os.path.basename(self.attachment.name)
|
||||||
|
|
||||||
attachment = models.FileField(upload_to=rename_attachment,
|
attachment = models.FileField(upload_to=rename_attachment,
|
||||||
help_text=_('Select file to attach'))
|
help_text=_('Select file to attach'))
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ class EditStockItemTestResultForm(HelperForm):
|
|||||||
'test',
|
'test',
|
||||||
'result',
|
'result',
|
||||||
'value',
|
'value',
|
||||||
|
'attachment',
|
||||||
'notes',
|
'notes',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -261,6 +261,17 @@ class StockItemTestResultCreate(AjaxCreateView):
|
|||||||
form = super().get_form()
|
form = super().get_form()
|
||||||
form.fields['stock_item'].widget = HiddenInput()
|
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
|
return form
|
||||||
|
|
||||||
|
|
||||||
@ -278,6 +289,8 @@ class StockItemTestResultEdit(AjaxUpdateView):
|
|||||||
form = super().get_form()
|
form = super().get_form()
|
||||||
|
|
||||||
form.fields['stock_item'].widget = HiddenInput()
|
form.fields['stock_item'].widget = HiddenInput()
|
||||||
|
|
||||||
|
form.fields['attachment'].queryset = self.object.stock_item.attachments.all()
|
||||||
|
|
||||||
return form
|
return form
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user