mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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"
|
||||
|
||||
def __str__(self):
|
||||
return os.path.basename(self.attachment.name)
|
||||
|
||||
attachment = models.FileField(upload_to=rename_attachment,
|
||||
help_text=_('Select file to attach'))
|
||||
|
||||
|
@ -46,6 +46,7 @@ class EditStockItemTestResultForm(HelperForm):
|
||||
'test',
|
||||
'result',
|
||||
'value',
|
||||
'attachment',
|
||||
'notes',
|
||||
]
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user