diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index d1add67d9d..26dd97b848 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -2,6 +2,7 @@ JSON API for the Stock app """ +from django.db.models.query import QuerySet from django_filters.rest_framework import FilterSet, DjangoFilterBackend from django_filters import NumberFilter @@ -931,6 +932,15 @@ class StockAttachmentList(generics.ListCreateAPIView, AttachmentMixin): ] +class StockAttachmentDetail(generics.RetrieveUpdateDestroyAPIView, AttachmentMixin): + """ + Detail endpoint for StockItemAttachment + """ + + queryset = StockItemAttachment.objects.all() + serializer_class = StockItemAttachmentSerializer + + class StockItemTestResultList(generics.ListCreateAPIView): """ API endpoint for listing (and creating) a StockItemTestResult object. @@ -1133,6 +1143,7 @@ stock_api_urls = [ url(r'location/', include(location_endpoints)), # These JSON endpoints have been replaced (for now) with server-side form rendering - 02/06/2019 + # TODO: Remove server-side forms for stock adjustment!!! url(r'count/?', StockCount.as_view(), name='api-stock-count'), url(r'add/?', StockAdd.as_view(), name='api-stock-add'), url(r'remove/?', StockRemove.as_view(), name='api-stock-remove'), @@ -1140,6 +1151,7 @@ stock_api_urls = [ # Base URL for StockItemAttachment API endpoints url(r'^attachment/', include([ + url(r'^(?P\d+)/', StockAttachmentDetail.as_view(), name='api-stock-attachment-detail'), url(r'^$', StockAttachmentList.as_view(), name='api-stock-attachment-list'), ])), diff --git a/InvenTree/stock/templates/stock/item_attachments.html b/InvenTree/stock/templates/stock/item_attachments.html index abd89c57c3..f5e9f8c4fc 100644 --- a/InvenTree/stock/templates/stock/item_attachments.html +++ b/InvenTree/stock/templates/stock/item_attachments.html @@ -61,12 +61,18 @@ $("#new-attachment").click(function() { $("#attachment-table").on('click', '.attachment-edit-button', function() { var button = $(this); - var url = `/stock/item/attachment/${button.attr('pk')}/edit/`; + var pk = button.attr('pk'); - launchModalForm(url, - { - reload: true, - }); + var url = `/api/stock/attachment/${pk}/`; + + constructForm(url, { + fields: { + attachment: {}, + comment: {}, + }, + title: '{% trans "Edit Attachment" %}', + reload: true + }); }); $("#attachment-table").on('click', '.attachment-delete-button', function() { diff --git a/InvenTree/stock/urls.py b/InvenTree/stock/urls.py index 01eb6f4704..eb0acbbef2 100644 --- a/InvenTree/stock/urls.py +++ b/InvenTree/stock/urls.py @@ -64,7 +64,6 @@ stock_urls = [ # URLs for StockItem attachments url(r'^item/attachment/', include([ - url(r'^(?P\d+)/edit/', views.StockItemAttachmentEdit.as_view(), name='stock-item-attachment-edit'), url(r'^(?P\d+)/delete/', views.StockItemAttachmentDelete.as_view(), name='stock-item-attachment-delete'), ])), diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 3608d5d553..5b41bfe1b2 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -255,23 +255,6 @@ class StockLocationQRCode(QRCodeView): return None -class StockItemAttachmentEdit(AjaxUpdateView): - """ - View for editing a StockItemAttachment object. - """ - - model = StockItemAttachment - form_class = StockForms.EditStockItemAttachmentForm - ajax_form_title = _("Edit Stock Item Attachment") - - def get_form(self): - - form = super().get_form() - form.fields['stock_item'].widget = HiddenInput() - - return form - - class StockItemAttachmentDelete(AjaxDeleteView): """ View for deleting a StockItemAttachment object.