diff --git a/InvenTree/order/api.py b/InvenTree/order/api.py index 74d94b12f4..a128130f39 100644 --- a/InvenTree/order/api.py +++ b/InvenTree/order/api.py @@ -259,6 +259,15 @@ class SOAttachmentList(generics.ListCreateAPIView, AttachmentMixin): ] +class SOAttachmentDetail(generics.RetrieveUpdateAPIView, AttachmentMixin): + """ + Detail endpoint for SalesOrderAttachment + """ + + queryset = SalesOrderAttachment.objects.all() + serializer_class = SOAttachmentSerializer + + class SOList(generics.ListCreateAPIView): """ API endpoint for accessing a list of SalesOrder objects. @@ -579,6 +588,7 @@ order_api_urls = [ # API endpoints for sales ordesr url(r'^so/', include([ url(r'attachment/', include([ + url(r'^(?P\d+)/$', SOAttachmentDetail.as_view(), name='api-so-attachment-detail'), url(r'^.*$', SOAttachmentList.as_view(), name='api-so-attachment-list'), ])), diff --git a/InvenTree/order/templates/order/so_attachments.html b/InvenTree/order/templates/order/so_attachments.html index b868aea48e..90ba49a0ea 100644 --- a/InvenTree/order/templates/order/so_attachments.html +++ b/InvenTree/order/templates/order/so_attachments.html @@ -23,7 +23,7 @@ enableDragAndDrop( '#attachment-dropzone', - "{% url 'so-attachment-create' %}", + '{% url "api-so-attachment-list" %}', { data: { order: {{ order.id }}, @@ -36,20 +36,36 @@ enableDragAndDrop( ); $("#new-attachment").click(function() { - launchModalForm("{% url 'so-attachment-create' %}?order={{ order.id }}", - { - reload: true, - } - ); + + constructForm('{% url "api-so-attachment-list" %}', { + method: 'POST', + fields: { + attachment: {}, + comment: {}, + order: { + value: {{ order.pk }}, + hidden: true + } + }, + reload: true, + title: '{% trans "Add Attachment" %}' + }); }); $("#attachment-table").on('click', '.attachment-edit-button', function() { var button = $(this); - var url = `/order/sales-order/attachment/${button.attr('pk')}/edit/`; + var pk = button.attr('pk'); - launchModalForm(url, { + var url = `/api/order/so/attachment/${pk}/`; + + constructForm(url, { + fields: { + attachment: {}, + comment: {}, + }, reload: true, + title: '{% trans "Edit Attachment" %}', }); }); diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py index 692f12f298..db76306b3c 100644 --- a/InvenTree/order/urls.py +++ b/InvenTree/order/urls.py @@ -89,8 +89,6 @@ sales_order_urls = [ ])), url(r'^attachment/', include([ - url(r'^new/', views.SalesOrderAttachmentCreate.as_view(), name='so-attachment-create'), - url(r'^(?P\d+)/edit/', views.SalesOrderAttachmentEdit.as_view(), name='so-attachment-edit'), url(r'^(?P\d+)/delete/', views.SalesOrderAttachmentDelete.as_view(), name='so-attachment-delete'), ])), diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index 8df386e8b8..9cf53ec51c 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -96,66 +96,6 @@ class SalesOrderDetail(InvenTreeRoleMixin, DetailView): template_name = 'order/sales_order_detail.html' -class SalesOrderAttachmentCreate(AjaxCreateView): - """ View for creating a new SalesOrderAttachment """ - - model = SalesOrderAttachment - form_class = order_forms.EditSalesOrderAttachmentForm - ajax_form_title = _('Add Sales Order Attachment') - - def save(self, form, **kwargs): - """ - Save the user that uploaded the attachment - """ - - attachment = form.save(commit=False) - attachment.user = self.request.user - attachment.save() - - def get_data(self): - return { - 'success': _('Added attachment') - } - - def get_initial(self): - initials = super().get_initial().copy() - - try: - initials['order'] = SalesOrder.objects.get(id=self.request.GET.get('order', None)) - except (ValueError, SalesOrder.DoesNotExist): - pass - - return initials - - def get_form(self): - """ Hide the 'order' field """ - - form = super().get_form() - form.fields['order'].widget = HiddenInput() - - return form - - -class SalesOrderAttachmentEdit(AjaxUpdateView): - """ View for editing a SalesOrderAttachment object """ - - model = SalesOrderAttachment - form_class = order_forms.EditSalesOrderAttachmentForm - ajax_form_title = _("Edit Attachment") - - def get_data(self): - return { - 'success': _('Attachment updated') - } - - def get_form(self): - form = super().get_form() - - form.fields['order'].widget = HiddenInput() - - return form - - class PurchaseOrderAttachmentDelete(AjaxDeleteView): """ View for deleting a PurchaseOrderAttachment """